123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\OrderImportFromC as OIFCModel;
- use app\BaseController;
- use Exception;
- use think\facade\Db;
- use think\facade\Validate;
- //C端订单导入及处理类
- class OrderImport extends Base
- {
- //订单导入
- public function import()
- {
- $param = $this->request->only(['token', 'list'], 'post', 'trim');
- $val_params = Validate::rule(['token' => 'require', 'list' => 'require|array']);
- if (!$val_params->check($param)) throw new \think\Exception($val_params->getError());
- Db::startTrans();
- try {
- $userinfo = GetUserInfo($param['token']);
- $createrid = isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0;
- $creater = isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : "";
- $val = Validate::rule([
- 'platform_code|平台订单号' => 'require|length:0,255',
- 'po_code|其他单号' => 'length:0,255',
- 'platform_time|平台下单时间' => 'require|date',
- 'sale_source|销售渠道' => 'require|length:0,255',
- 'good_code|商品编号' => 'require|length:0,255',
- 'price|单价' => 'require|float',
- 'num|数量' => 'require|number',
- 'before_discount_all_price|优惠前总金额' => 'require|float',
- 'discount_price|优惠金额' => 'require|float',
- 'after_price|商品优惠后金额' => 'require|float',
- 'activity_name|优惠活动名称' => 'require|length:0,255',
- 'mode|收费模式' => 'require|length:0,255',
- 'order_remark|订单备注' => 'length:0,255',
- 'contactor|收货人' => 'require|length:0,255',
- 'mobile|联系电话' => 'require|length:0,20',
- 'addr|联系地址' => 'require|length:0,255',
- ]);
- $insert_data = [];
- foreach ($param['list'] as $key => $value) {
- if (!$val->check($value)) throw new \think\Exception('第' . (string)($key + 1) . '行数据格式有问题,' . $val->getError());
- else {
- $value['createrid'] = $createrid;
- $value['creater'] = $creater;
- $insert_data[] = $value;
- }
- }
- $res = Db::name('order_import_from_c')
- ->limit(100)
- ->insertAll($insert_data);
- if ($res) {
- Db::commit();
- return app_show(0, "导入成功,共" . (string)$res . '条记录');
- } else {
- Db::rollback();
- return error_show(1005, '导入失败');
- }
- } catch (Exception $exception) {
- Db::rollback();
- return error_show(1005, $exception->getMessage());
- }
- }
- //查看订单录入列表
- public function getImportList()
- {
- $param = $this->request->only([
- 'status' => 0,
- 'platform_code' => '',
- 'po_code' => '',
- 'platform_time_start' => '',
- 'platform_time_end' => '',
- 'addtime_start' => '',
- 'addtime_end' => '',
- 'good_code' => '',
- 'page' => 1,
- 'size' => 15,
- ], 'post', 'trim');
- $where = [];
- if ($param['status']) $where[] = ['c.status', '=', $param['status']];
- if ($param['platform_code']) $where[] = ['c.platform_code', 'like', '%' . $param['platform_code'] . '%'];
- if ($param['po_code']) $where[] = ['c.po_code', 'like', '%' . $param['po_code'] . '%'];
- if ($param['platform_time_start'] && $param['platform_time_end']) $where[] = ['c.platform_time', 'between', [$param['platform_time_start'], $param['platform_time_end']]];
- if ($param['addtime_start'] && $param['addtime_end']) $where[] = ['c.addtime', 'between', [$param['addtime_start'], $param['addtime_end']]];
- if ($param['good_code']) $where[] = ['c.good_code', 'like', '%' . $param['good_code'] . '%'];
- $db = OIFCModel::alias('c')->where($where);
- $total = $db->count('id');
- $list = $db
- ->page($param['page'], $param['size'])
- ->order('id', 'desc')
- ->select()
- ->toArray();
- return app_show(0, "获取成功", ['list' => $list, 'count' => $total]);
- }
- }
|