diff --git a/app/admin/controller/accounts_receivable/AccountsReceivableController.php b/app/admin/controller/accounts_receivable/AccountsReceivableController.php new file mode 100644 index 000000000..8359978a0 --- /dev/null +++ b/app/admin/controller/accounts_receivable/AccountsReceivableController.php @@ -0,0 +1,46 @@ +dataLists(new AccountsReceivableLists()); + } + + public function edit() + { + $params = (new AppUpdateValidate())->post()->goCheck('edit'); + $result = AccountsReceivableLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(AccountsReceivableLogic::getError()); + } + + public function delete() + { + $params = (new AppUpdateValidate())->post()->goCheck('delete'); + AccountsReceivableLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + public function detail() + { + $params = (new AppUpdateValidate())->goCheck('detail'); + $result = AccountsReceivableLogic::detail($params); + return $this->data($result); + } + +} \ No newline at end of file diff --git a/app/admin/lists/AccountsReceivableLists.php b/app/admin/lists/AccountsReceivableLists.php new file mode 100644 index 000000000..16a6b70f0 --- /dev/null +++ b/app/admin/lists/AccountsReceivableLists.php @@ -0,0 +1,60 @@ + ['store_id', 'user_id'], + ]; + } + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function lists(): array + { + $query = AccountsReceivable::where($this->searchWhere); + if (!empty($this->params['order_sn'])) { + $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); + $query->whereIn('order_id', $orderIds); + } + return $query + ->with('info') + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + /** + * @notes 获取数量 + * @return int + */ + public function count(): int + { + $query = AccountsReceivable::where($this->searchWhere); + if (!empty($this->params['order_sn'])) { + $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); + $query->whereIn('order_id', $orderIds); + } + return $query->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/AccountsReceivableLogic.php b/app/admin/logic/AccountsReceivableLogic.php new file mode 100644 index 000000000..2e363e7e0 --- /dev/null +++ b/app/admin/logic/AccountsReceivableLogic.php @@ -0,0 +1,122 @@ +order_id = $order['id']; + $model->store_id = $order['store_id']; + $model->user_id = $order['uid']; + $model->deadline = time() + 86400 * 15; + $model->total_debt = $order['total_price']; + $model->surplus_debt = $order['total_price']; + $model->save(); + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author admin + * @date 2024/12/20 10:52 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ActivityZone::where('id', $params['id'])->update([ + 'form_id' => $params['form_id'], + 'product_id' => $params['product_id'], + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author admin + * @date 2024/12/20 10:52 + */ + public static function delete(array $params): bool + { + return ActivityZone::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author admin + * @date 2024/12/20 10:52 + */ + public static function detail($params): array + { + return ActivityZone::findOrEmpty($params['id'])->toArray(); + } + + public function addProduct($product) + { + $activityFormId1 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['two_cate_id']])->column('id'); + $activityFormId2 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['cate_id']])->column('id'); + $activityFormIds = array_unique(array_merge($activityFormId1, $activityFormId2)); + foreach ($activityFormIds as $activityFormId) { + $activityZone = new ActivityZone(); + $activityZone->form_id = $activityFormId; + $activityZone->product_id = $product['id']; + $activityZone->save(); + } + } + + public function updateProduct($productId, $product) + { + $product['id'] = $productId; + $formIds = ActivityZone::where('product_id', $productId)->column('form_id'); + if (empty($formIds)) { + $this->addProduct($product); + return; + } + $forms = ActivityZoneForm::whereIn('id', $formIds)->select()->toArray(); + foreach ($forms as $form) { + $cateIds = explode(',', $form['cate_ids']); + if (!in_array($product['two_cate_id'], $cateIds) && !in_array($product['cate_id'], $cateIds)) { + ActivityZone::where('product_id', $productId)->where('form_id', $form['id'])->update(['delete_time' => time()]); + } + $this->addProduct($product); + } + } + + public function deleteProduct($productId) + { + ActivityZone::where('product_id', $productId)->update(['delete_time' => time()]); + } + +} \ No newline at end of file diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 27b5b6c4d..f8271fe06 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -2,6 +2,7 @@ namespace app\admin\logic\beforehand_order; +use app\admin\logic\AccountsReceivableLogic; use app\admin\logic\store_branch_product\StoreBranchProductLogic; use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic; @@ -129,6 +130,7 @@ class BeforehandOrderLogic extends BaseLogic 'address' => $params['address'] ?? '', 'mark' => $params['mark'] ?? '', 'order_type' => $order_type, + 'is_arrears' => $params['is_arrears'] ?? 1, 'other_data' => json_encode($params['other_data'], true) ]); /** 添加审批记录 */ @@ -452,6 +454,9 @@ class BeforehandOrderLogic extends BaseLogic throw new BusinessException('出库失败,预订单更新出错'); } BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]); + if ($order['is_arrears'] == 2) { + AccountsReceivableLogic::add($order); + } self::confirm(['id' => $params['bhoid']]); Db::commit(); return true; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index ade3ec1ed..cbcbd9d44 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -501,8 +501,10 @@ class PayNotifyLogic extends BaseLogic if ($order['other_uid'] > 0) { $uid = $order['other_uid']; } - $cashFlowLogic = new CashFlowLogic(); - $cashFlowLogic->insert($order['store_id'], $order['price'], $orderSn); + if ($type == 'wechat') { + $cashFlowLogic = new CashFlowLogic(); + $cashFlowLogic->insert($order['store_id'], $order['price'], $orderSn); + } PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); diff --git a/app/common/model/finance/AccountsReceivable.php b/app/common/model/finance/AccountsReceivable.php new file mode 100644 index 000000000..1747c8d94 --- /dev/null +++ b/app/common/model/finance/AccountsReceivable.php @@ -0,0 +1,20 @@ +hasMany(AccountsReceivableInfo::class, 'accounts_receivable_id', 'id'); + } + +} diff --git a/app/common/model/finance/AccountsReceivableInfo.php b/app/common/model/finance/AccountsReceivableInfo.php new file mode 100644 index 000000000..b5c469f41 --- /dev/null +++ b/app/common/model/finance/AccountsReceivableInfo.php @@ -0,0 +1,14 @@ +