| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace addons\CloudStock\common\models;
- use common\components\export\CsvTool;
- use common\enums\DownloadEnum;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\common\Download;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_cloud_stock_order_batch_delivery_error".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $batch_delivery_id qimall_order_batch_delivery.id
- * @property string $order_no 订单号
- * @property string $express_no 物流单号
- * @property string $content 错误原因
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class CloudStockOrderBatchDeliveryError extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_cloud_stock_order_batch_delivery_error';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'batch_delivery_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['content'], 'required'],
- [['content'], 'string'],
- [['order_no', 'express_no'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'batch_delivery_id' => 'Batch Delivery ID',
- 'order_no' => 'Order No',
- 'express_no' => 'Express No',
- 'content' => 'Content',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params)
- {
- try {
- $mobel = new self();
- if (!$mobel->load($params, '') || !$mobel->save()) throw new \Exception($mobel->getErrorMessage());
- return $mobel;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- public static function exportHandle(array $data) {
- $download_id = $data['download_id'] ?? 0;
- $download = Download::findOne(['id' => $download_id]);
- if ($download) {
- try {
- $params = json_decode($download->params,true);
- $filename = $download->name;
- $type = $download->type;
- $list = self::find()->select("order_no,express_no,content")->where(['mall_id' => $params['mall_id'], 'batch_delivery_id' => $params['batch_delivery_id'], 'status' => StatusEnum::ENABLED])->asArray()->all();
- $have_select_field_arr = ['订单号','物流单号','失败原因'];
- $csv = new CsvTool();
- $csv->filename = $filename;
- $csv->file_dirname = DownloadEnum::getTypeStorageDirMap($type);
- $csv->export_mode = CsvTool::EXPORT_MODE_ASYNC;
- $csv->header = $have_select_field_arr;
- foreach ($list as $item) {
- is_numeric($item['express_no']) && $item['express_no'] = $item['express_no'] . "\t";
- $rows[] = $item;
- }
- $csv->data = $rows;
- $csv->export();
- $csv->updateDown($download,$params['mall_id']);
- return true;
- } catch (\Exception $e) {
- $download->status = 3;
- $res = $download->save();
- self::setStaticError($e->getMessage());
- return $e->getMessage();
- }
- }
- }
- }
|