diff --git a/app/admin/controller/financial/FinancialRecordController.php b/app/admin/controller/financial/FinancialRecordController.php new file mode 100644 index 0000000..73de7aa --- /dev/null +++ b/app/admin/controller/financial/FinancialRecordController.php @@ -0,0 +1,29 @@ +dataLists(new FinancialRecordLists()); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/supplier/SupplierBindGoodsController.php b/app/admin/controller/supplier/SupplierBindGoodsController.php new file mode 100644 index 0000000..d89c48d --- /dev/null +++ b/app/admin/controller/supplier/SupplierBindGoodsController.php @@ -0,0 +1,92 @@ +dataLists(new SupplierBindGoodsLists()); + } + + + /** + * @notes 添加供应商商品绑定 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function add() + { + $params = $this->request->post(); + $result = SupplierBindGoodsLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SupplierBindGoodsLogic::getError()); + } + + + /** + * @notes 编辑供应商商品绑定 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function edit() + { + $params = (new SupplierBindGoodsValidate())->post()->goCheck('edit'); + $result = SupplierBindGoodsLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SupplierBindGoodsLogic::getError()); + } + + + /** + * @notes 删除供应商商品绑定 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function delete() + { + $params = (new SupplierBindGoodsValidate())->post()->goCheck('delete'); + SupplierBindGoodsLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取供应商商品绑定详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function detail() + { + $params = (new SupplierBindGoodsValidate())->goCheck('detail'); + $result = SupplierBindGoodsLogic::detail($params); + return $this->data($result); + } +} \ No newline at end of file diff --git a/app/admin/lists/financial/FinancialRecordLists.php b/app/admin/lists/financial/FinancialRecordLists.php new file mode 100644 index 0000000..5eb606c --- /dev/null +++ b/app/admin/lists/financial/FinancialRecordLists.php @@ -0,0 +1,65 @@ +searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $item['user_nickname']=User::where('id',$item['user_id'])->value('nickname'); + $item['financial_pm']=$item['financial_pm']==0?"支出":"获得"; + if($item['type']=='商户'){ + $item['mer_name']=Merchant::where('mer_id',$item['mer_id'])->value('mer_name'); + } + return $item; + }) + ->toArray(); + } + + /** + * @notes 获取流水数量 + * @return int + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function count(): int + { + return FinancialRecord::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/supplier/SupplierBindGoodsLists.php b/app/admin/lists/supplier/SupplierBindGoodsLists.php new file mode 100644 index 0000000..ebec15d --- /dev/null +++ b/app/admin/lists/supplier/SupplierBindGoodsLists.php @@ -0,0 +1,74 @@ + ['supplier_id'], + ]; + } + + + /** + * @notes 获取供应商商品绑定列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function lists(): array + { + return SupplierBindGoods::where($this->searchWhere)->withoutField(['update_time','delete_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $goods=Goods::where('id',$item['goods_id'])->field('name,class,spec,imgs')->find(); + if($goods){ + $item['class_name']=Goodsclass::where('id',$goods['class'])->value('name'); + $item['goods_name']=$goods['name']; + $item['imgs']=$goods['imgs']; + $item['spec']=$goods['spec']; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取供应商商品绑定数量 + * @return int + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function count(): int + { + return SupplierBindGoods::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/operation/OpurchaseclassLogic.php b/app/admin/logic/operation/OpurchaseclassLogic.php index 6c60941..c95ec39 100644 --- a/app/admin/logic/operation/OpurchaseclassLogic.php +++ b/app/admin/logic/operation/OpurchaseclassLogic.php @@ -12,6 +12,7 @@ use app\common\model\opurchase\Opurchaseinfo; use app\common\model\order\Cart; use app\common\model\retail\Cashierclass; use app\common\model\supplier\Supplier; +use app\common\model\supplier\SupplierBindGoods; use support\Log; use think\facade\Db; @@ -195,38 +196,30 @@ class OpurchaseclassLogic extends BaseLogic public static function createSupplierGoods($goods) { try { - $sys_labels = Goods::where('id', $goods['goods'])->value('sys_labels'); - $supplier_arr = []; - $goods_offer = []; - - if ($sys_labels) { - $sys_labels_arr = explode(',', $sys_labels); - foreach ($sys_labels_arr as $k => $v) { - if ($v > 0) { - $supplier = Supplier::whereLike('sys_labels', "%," . $v . ",%")->field('id,mer_name')->select(); - foreach ($supplier as $key => $value) { - $supplier_arr[] = $value; - } + $supplier_arr=SupplierBindGoods::where('goods_id')->column('supplier_id'); + if($supplier_arr){ + $supplier_arr=array_unique($supplier_arr); + foreach ($supplier_arr as $k => $v) { + $goods_offer[] = [ + 'supplier_id' => $v['id'], + 'goods_id' => $goods['goods'], + 'order_id' => $goods['pid'], + 'price' => 0, + 'need_num' => $goods['nums'], + 'create_time'=>time() + ]; + } + if (count($goods_offer) >= 1) { + $res = OpurchaseGoodsOffer::insertAll($goods_offer); + if ($res) { + Opurchaseinfo::where('id',$goods['id'])->update(['is_push'=>1]); + return $goods_offer; } } + }else{ + } - foreach ($supplier_arr as $k => $v) { - $goods_offer[] = [ - 'supplier_id' => $v['id'], - 'goods_id' => $goods['goods'], - 'order_id' => $goods['pid'], - 'price' => 0, - 'need_num' => $goods['nums'], - 'create_time'=>time() - ]; - } - if (count($goods_offer) >= 1) { - $res = OpurchaseGoodsOffer::insertAll($goods_offer); - if ($res) { - Opurchaseinfo::where('id',$goods['id'])->update(['is_push'=>1]); - return $goods_offer; - } - } + } catch (\Exception $e) { self::setError($e->getMessage()); Log::error('添加采购订单报价失败:' . $e->getMessage()); diff --git a/app/admin/logic/supplier/SupplierBindGoodsLogic.php b/app/admin/logic/supplier/SupplierBindGoodsLogic.php new file mode 100644 index 0000000..58b3126 --- /dev/null +++ b/app/admin/logic/supplier/SupplierBindGoodsLogic.php @@ -0,0 +1,105 @@ +$item['supplier_id'], + 'goods_id'=>$item['goods_id'], + 'goods_name'=>$item['goods_name'], + 'goods_price'=>$item['price'], + ]; + } + (new SupplierBindGoods())->saveAll($list); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑供应商管理 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + + SupplierBindGoods::where('id', $params['id'])->update([ + 'goods_id'=>$params['goods_id'], + 'supplier_id'=>$params['supplier_id'], + 'price'=>$params['price'], + 'goods_name'=>$params['goods_name'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除供应商管理 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public static function delete(array $params): bool + { + return SupplierBindGoods::destroy($params['id']); + } + + + /** + * @notes 获取供应商管理详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public static function detail($params): array + { + $data = SupplierBindGoods::findOrEmpty($params['id']); + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/supplier/SupplierBindGoodsValidate.php b/app/admin/validate/supplier/SupplierBindGoodsValidate.php new file mode 100644 index 0000000..26376c3 --- /dev/null +++ b/app/admin/validate/supplier/SupplierBindGoodsValidate.php @@ -0,0 +1,85 @@ + 'require', + 'supplier_id' => 'require', + 'goods_name' => 'require', + 'price' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'goods_id' => '商品id', + 'supplier_id' => '供应链id', + 'goods_name' => '商品名称', + 'price' => '价格', + ]; + + /** + * @notes 添加场景 + * @return SupplierValidate + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function sceneAdd() + { + return $this->only(['goods_id']); + } + + + /** + * @notes 编辑场景 + * @return SupplierValidate + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function sceneEdit() + { + } + + + /** + * @notes 删除场景 + * @return SupplierValidate + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SupplierValidate + * @author likeadmin + * @date 2024/04/27 14:33 + */ + public function sceneDetail() + { + return $this->only(['id']); + } +} diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 14d2e5a..f33507d 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -14,7 +14,7 @@ class OrderEnum * @MERCHANT_ORDER_PAY 商户订单支付 * @PLATFORM_ORDER_OBTAINS 平台订单获得 * @SUPPLIER_ORDER_OBTAINS 供应链订单获得 - * @MERCHANT_ORDER_PAY 平台订单支付 + * @PLATFORM_ORDER_PAY 平台订单支付 */ const USER_ORDER_PAY = 1; const MERCHANT_ORDER_OBTAINS = 2; @@ -45,7 +45,30 @@ class OrderEnum const PLATFORM =2; const SUPPLIER =3; + /** + * @notes 获取支付类型 + * @param bool $value + * @return string|string[] + * @author 段誉 + * @date 2023/2/23 15:36 + */ + public static function getFinancialType($value = true) + { + $data = [ + self::USER_ORDER_PAY=>'用户订单支付', + self::MERCHANT_ORDER_PAY=>'商户订单支付', + self::PLATFORM_ORDER_PAY=>'平台订单支付', + self::MERCHANT_ORDER_OBTAINS=>'商户订单提现', + self::ORDER_HANDLING_FEES=>'订单手续费', + self::PLATFORM_ORDER_OBTAINS=>'平台订单获得', + self::SUPPLIER_ORDER_OBTAINS=>'供应商订单获得', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } } \ No newline at end of file diff --git a/app/common/model/financial/FinancialRecord.php b/app/common/model/financial/FinancialRecord.php new file mode 100644 index 0000000..ff4037e --- /dev/null +++ b/app/common/model/financial/FinancialRecord.php @@ -0,0 +1,40 @@ +'用户', + '1'=>'商户', + '2'=>'平台', + '3'=>'供应链', + ]; + return $type[$value]??'无属性'; + } + + /** + * @notes 获取流水类型 + */ + public function getFinancialTypeAttr($value){ + return OrderEnum::getFinancialType($value)??'无属性'; + } +} \ No newline at end of file diff --git a/app/common/model/supplier/SupplierBindGoods.php b/app/common/model/supplier/SupplierBindGoods.php new file mode 100644 index 0000000..dd48a4f --- /dev/null +++ b/app/common/model/supplier/SupplierBindGoods.php @@ -0,0 +1,22 @@ +