123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace app\abutment\logic;
- use think\Exception;
- use think\facade\Db;
- class Filing
- {
- //列表
- public static function list(array $data = [])
- {
- $where = [['is_del', '=', '0']];
- if ($data['cat_id'] != '') $where[] = ['cat_id', '=', $data['cat_id']];
- if ($data['start_date'] != '' && $data['end_date'] != '') $where[] = ['addtime', 'between', [$data['start_date'], $data['end_date']]];
- if ($data['filingCode'] != '') $where[] = ['filingCode', 'like', '%' . $data['filingCode'] . '%'];
- if ($data['status'] != '') $where[] = ['status', '=', $data['status']];
- if ($data['good_name'] != '') $where[] = ['good_name', 'like', '%' . $data['good_name'] . '%'];
- if ($data['companyName'] != '') $where[] = ['companyName', 'like', '%' . $data['companyName'] . '%'];
- if ($data['companyCode'] != '') $where[] = ['companyCode', 'like', '%' . $data['companyCode'] . '%'];
- if ($data['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $data['orderCode'] . '%'];
- if ($data['supplierNo'] != '') $where[] = ['supplierNo', '=', $data['supplierNo']];
- $count = Db::name('filing')
- ->where($where)
- ->count('id');
- $list = Db::name('filing')
- ->field('id,filingCode,cat_id,good_name,num,good_img,price,expect_service,companyName,companyCode,status,addtime,"" catinfo,orderCode')
- ->where($where)
- ->page($data['page'], $data['size'])
- ->order('id', 'desc')
- ->select()
- ->toArray();
- $all_cat = [];
- foreach ($list as &$value) {
- if (!isset($all_cat[$value['cat_id']])) {
- $value['catinfo'] = $all_cat[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
- }
- }
- return json_show(0, '获取报备单列表成功', ['count' => $count, 'list' => $list]);
- }
- //添加
- public static function add(array $data = [])
- {
- if ($data['is_determine_price'] == 1) $data['cgd_charge'] = bcadd($data['price'], $data['expect_service'], 2);//确定售价时,采购价=售价+服务费
- else $data['price'] = bcsub($data['cgd_charge'], $data['expect_service'], 2);//不确定售价时,售价=采购价-服务费
- $customerName = Db::name('business')
- ->where(['companyNo' => $data['customerCode']])
- ->value('company', '');
- if ($customerName == '') return json_show(1004, '该业务公司不存在');
- $rs = Db::name('filing')
- ->strict(false)
- ->insert(array_merge($data, [
- 'customerName' => $customerName,
- 'filingCode' => makeNo('BM'),
- 'service_charge' => $data['expect_service'],//服务费与期望服务费一致
- 'specinfo' => json_encode($data['spec_list']),
- 'send_way' => 2,
- 'cert_fee' => 0,
- 'pakge_fee' => 0,
- 'cost_fee' => 0,
- 'mark_fee' => 0,
- 'demo_fee' => 0,
- 'open_fee' => 0,
- 'delivery_fee' => 0,
- 'is_gold_price' => 0,
- 'is_diff' => 0,
- 'apply_id' => request()->user['uid'],
- 'apply_name' => request()->user['nickname'],
- 'status' => 0,
- 'is_del' => 0,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- ]));
- return $rs ? json_show(0, '创建报备单成功') : json_show(1004, '创建报备单失败');
- }
- //详情
- public static function detail(array $data = [])
- {
- $rs = Db::name('filing')
- ->where(['is_del' => 0])
- ->where($data)
- ->withAttr('specinfo', function ($val) {
- return json_decode($val);
- })
- ->findOrEmpty();
- return json_show(0, '获取报备单详情成功', $rs);
- }
- //审核
- public static function status(array $data = [])
- {
- $rs = Db::name('filing')
- ->field('id,status')
- ->where(['is_del' => 0, 'id' => $data['id']])
- ->whereIn('status', [0, 2])
- ->findOrEmpty();
- if (empty($rs)) return json_show(1005, '该报备单不存在或不允许审核');
- $companyName = Db::name('customer_info')
- ->where(['is_del' => 0, 'companyNo' => $data['companyCode']])
- ->value('companyName', '');
- if ($companyName == '') return json_show(1005, '该客户不存在');
- $res = Db::name('filing')
- ->where(['is_del' => 0, 'id' => $data['id']])
- ->whereIn('status', [0, 2])
- ->update(array_merge($data, [
- 'companyName' => $companyName,
- 'updatetime' => date('Y-m-d H:i:s')
- ]));
- return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
- }
- //取消转单
- public static function cancel(array $data = [])
- {
- $rs = Db::name('filing')
- ->field('id,status')
- ->where(['is_del' => 0, 'id' => $data['id'], 'status' => 2, 'supplierNo' => $data['supplierNo']])
- ->findOrEmpty();
- if (empty($rs)) return json_show(1005, '该报备单不存在或不是待转单状态');
- $res = Db::name('filing')
- ->where(['is_del' => 0, 'id' => $data['id'], 'status' => 2])
- ->update(['status' => 5, 'updatetime' => date('Y-m-d H:i:s')]);
- return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
- }
- //转单
- public static function transfer(array $data = [])
- {
- $rs = Db::name('filing')
- ->field(true)
- ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
- ->findOrEmpty();
- if (empty($rs)) json_show(1005, '该报备单不存在或不允许转单');
- $date = date('Y-m-d H:i:s');
- Db::startTrans();
- try {
- Db::name('filing')
- ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
- ->update(['status' => 3, 'updatetime' => $date]);
- Db::commit();
- return json_show(0, '转单成功');
- } catch (Exception $exception) {
- Db::rollback();
- Db::name('filing')
- ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
- ->update(['status' => 4, 'updatetime' => $date, 'reason' => $exception->getMessage()]);
- return json_show(1005, $exception->getMessage());
- }
- }
- }
|