|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+namespace app\command;
|
|
|
4
|
+
|
|
|
5
|
+use app\common\model\store\order\StoreOrder;
|
|
|
6
|
+use app\common\model\user\UserCertification;
|
|
|
7
|
+use app\common\repositories\merchant\order\OrderGzcRepository;
|
|
|
8
|
+use app\common\repositories\merchant\order\OrderMerchantRepository;
|
|
|
9
|
+use app\common\repositories\store\order\StoreOrderRepository;
|
|
|
10
|
+use app\common\repositories\store\order\StoreOrderStatusRepository;
|
|
|
11
|
+use app\common\repositories\user\UserBillRepository;
|
|
|
12
|
+use app\common\repositories\user\UserRepository;
|
|
|
13
|
+use Carbon\Carbon;
|
|
|
14
|
+use think\console\Command;
|
|
|
15
|
+use think\console\Input;
|
|
|
16
|
+use think\console\Output;
|
|
|
17
|
+use think\facade\Db;
|
|
|
18
|
+use think\facade\Log;
|
|
|
19
|
+
|
|
|
20
|
+class CommercialAreaOrderIndependentAccount extends Command
|
|
|
21
|
+{
|
|
|
22
|
+ protected function configure()
|
|
|
23
|
+ {
|
|
|
24
|
+ // 指令配置
|
|
|
25
|
+ $this->setName('commercial-area-order-independent-account')
|
|
|
26
|
+ ->setDescription('商贸区订单分账');
|
|
|
27
|
+ }
|
|
|
28
|
+
|
|
|
29
|
+ protected function execute(Input $input, Output $output)
|
|
|
30
|
+ {
|
|
|
31
|
+ // @todo 商贸区订单分账
|
|
|
32
|
+ $this->doCommercialAreaOrderIndependentAccount([439,491,496]);
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * 商贸区订单分账
|
|
|
37
|
+ *
|
|
|
38
|
+ * @param $excludeMerId
|
|
|
39
|
+ * @param $timeLimit
|
|
|
40
|
+ * @return void
|
|
|
41
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
42
|
+ * @throws \think\db\exception\DbException
|
|
|
43
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
44
|
+ */
|
|
|
45
|
+ private function doCommercialAreaOrderIndependentAccount($excludeMerId = [], $timeLimit = 30)
|
|
|
46
|
+ {
|
|
|
47
|
+ // 商户信息
|
|
|
48
|
+ $merchants = [];
|
|
|
49
|
+// $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
|
|
50
|
+// $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
|
|
|
51
|
+// $OrderGzcRepository = app()->make(OrderGzcRepository::class);
|
|
|
52
|
+
|
|
|
53
|
+ /** @var StoreOrderRepository $storeOrderRepository */
|
|
|
54
|
+ $storeOrderRepository = app()->make(StoreOrderRepository::class);
|
|
|
55
|
+
|
|
|
56
|
+ $time = time();
|
|
|
57
|
+ // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
|
|
|
58
|
+ $status = [2, 3];
|
|
|
59
|
+ // 已支付、未结算
|
|
|
60
|
+ $where = ['paid' => 1, 'gzc' => 0, 'is_del' => 0, 'is_system_del' => 0];
|
|
|
61
|
+ // 普通订单 @todo 排除 特殊商户{$excludeMerId}:精彩生活区、会员区、复购区
|
|
|
62
|
+ $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')->whereIn('status', $status)
|
|
|
63
|
+ ->whereNotIn('mer_id', $excludeMerId)->cursor();
|
|
|
64
|
+ foreach ($cursor as $key => $value) {
|
|
|
65
|
+ $settlement_period_time = strtotime($value['create_time']) + $timeLimit * 24 * 3600;
|
|
|
66
|
+ // @todo 下单后第{$timeLimit}天后可分账
|
|
|
67
|
+ if ($settlement_period_time >= $time) {
|
|
|
68
|
+ if (!isset($merchants[$value['mer_id']])) {
|
|
|
69
|
+ $merchants[$value['mer_id']] = Db::name('merchant')->where('mer_id', $value['mer_id'])->find();
|
|
|
70
|
+ }
|
|
|
71
|
+ $group_order = Db::name('store_group_order')->alias('sgo')->where('sgo.group_order_id', $value['group_order_id'])->find();
|
|
|
72
|
+ // @todo 分账账号 496:表示{会员专区}账户;商贸区分账如下:成本分账到商户,利润分账到{会员专区}账户
|
|
|
73
|
+ $independentAccount = $storeOrderRepository->getIndependentAccount($value, $group_order, 496, $merchants[$value['mer_id']]['hf_member_id']);
|
|
|
74
|
+
|
|
|
75
|
+ // @todo 预分账处理
|
|
|
76
|
+ $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccount(
|
|
|
77
|
+ $value, $group_order, $independentAccount['api_key'], $independentAccount['hf_member_id'], $independentAccount['hf_platform_member_id'], $value['cost'], $value['con_pri']
|
|
|
78
|
+ );
|
|
|
79
|
+ Db::name("log")->insert(array('data' => '商贸区-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));//日志记录
|
|
|
80
|
+
|
|
|
81
|
+// Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
|
|
|
82
|
+// //新增入账明细记录
|
|
|
83
|
+// $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
|
|
|
84
|
+// $create = [
|
|
|
85
|
+// 'uid' => $online['uid'],
|
|
|
86
|
+// 'platform_no' => $orderId,
|
|
|
87
|
+// 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
|
|
|
88
|
+// 'user_name' => $certification['user_name'],
|
|
|
89
|
+// 'mobile' => $certification['mobile'],
|
|
|
90
|
+// 'user_card' => $certification['user_card'],
|
|
|
91
|
+// 'pension' => $pension,
|
|
|
92
|
+// 'order_type' => 2,
|
|
|
93
|
+// 'out_trade_no' => $online['order_sn']
|
|
|
94
|
+// ];
|
|
|
95
|
+// $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
|
|
|
96
|
+// $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
|
|
|
97
|
+// if ($test_user == 0 && $check <= 0) {
|
|
|
98
|
+// $OrderGzcRepository->create($create);
|
|
|
99
|
+// }
|
|
|
100
|
+// $order = StoreOrder::getInstance()->find($online['order_id']);
|
|
|
101
|
+// $order->gzc = 1;
|
|
|
102
|
+// $order->save();
|
|
|
103
|
+// });
|
|
|
104
|
+ }
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
|
|
|
108
|
+// $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
|
|
|
109
|
+// $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
|
|
110
|
+// $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
|
|
|
111
|
+// $OrderGzcRepository = app()->make(OrderGzcRepository::class);
|
|
|
112
|
+// foreach ($cursor as $online) {
|
|
|
113
|
+// $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
|
|
|
114
|
+// if ($online['mer_id'] == 496) {
|
|
|
115
|
+// if (!in_array($online['status'], [0, 1, 2, 3])) {
|
|
|
116
|
+// continue;
|
|
|
117
|
+// }
|
|
|
118
|
+// if (time() < strtotime($online['pay_time']) + 3600 * 24) {
|
|
|
119
|
+// Log::info('还没有到收货后' . $timeLimit . '天');
|
|
|
120
|
+// continue;
|
|
|
121
|
+// }
|
|
|
122
|
+// } else {
|
|
|
123
|
+// if (!in_array($online['status'], [2, 3])) {
|
|
|
124
|
+// continue;
|
|
|
125
|
+// }
|
|
|
126
|
+// if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
|
|
|
127
|
+// Log::info('还没有到收货后' . $timeLimit . '天');
|
|
|
128
|
+// continue;
|
|
|
129
|
+// }
|
|
|
130
|
+// }
|
|
|
131
|
+//
|
|
|
132
|
+// $StoreOrderRepository = app()->make(StoreOrderRepository::class);
|
|
|
133
|
+// Db::transaction(function () use ($online, $StoreOrderRepository) {
|
|
|
134
|
+// $order = StoreOrder::getInstance()->find($online['order_id']);
|
|
|
135
|
+// $order->is_settlement = 1;
|
|
|
136
|
+// $order->settlement_time = date('Y-m-d H:i:s');
|
|
|
137
|
+// $order->save();
|
|
|
138
|
+//
|
|
|
139
|
+// // 结算积分
|
|
|
140
|
+// $user_sign_score_list = Db::name('user_sign_score')
|
|
|
141
|
+// ->where('status', -1)
|
|
|
142
|
+// ->where('order_id', $online['order_id'])
|
|
|
143
|
+// ->whereIn('type', [1, 2])
|
|
|
144
|
+// ->select()
|
|
|
145
|
+// ->toArray();
|
|
|
146
|
+// foreach ($user_sign_score_list as $user_sign_score) {
|
|
|
147
|
+// // 修改积分
|
|
|
148
|
+// Db::name('user')
|
|
|
149
|
+// ->where('uid', $user_sign_score['uid'])
|
|
|
150
|
+// ->inc('score', (float)$user_sign_score['reward_socre'])
|
|
|
151
|
+// ->update();
|
|
|
152
|
+// Db::name('user_sign_score')
|
|
|
153
|
+// ->where('status', -1)
|
|
|
154
|
+// ->where('id', $user_sign_score['id'])
|
|
|
155
|
+// ->update([
|
|
|
156
|
+// 'status' => 1,
|
|
|
157
|
+// 'settlement_time' => date('Y-m-d H:i:s')
|
|
|
158
|
+// ]);
|
|
|
159
|
+// }
|
|
|
160
|
+//
|
|
|
161
|
+// // 结算红包
|
|
|
162
|
+// $user_sign_hongbao_list = Db::name('user_sign_hongbao')
|
|
|
163
|
+// ->where('status', -1)
|
|
|
164
|
+// ->where('order_id', $online['order_id'])
|
|
|
165
|
+// ->whereIn('type', [1, 2])
|
|
|
166
|
+// ->select()
|
|
|
167
|
+// ->toArray();
|
|
|
168
|
+// foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
|
|
|
169
|
+// // 修改红包
|
|
|
170
|
+// Db::name('user')
|
|
|
171
|
+// ->where('uid', $user_sign_hongbao['uid'])
|
|
|
172
|
+// ->inc('hongbao', (float)$user_sign_hongbao['number'])
|
|
|
173
|
+// ->update();
|
|
|
174
|
+// Db::name('user_sign_hongbao')
|
|
|
175
|
+// ->where('status', -1)
|
|
|
176
|
+// ->where('id', $user_sign_hongbao['id'])
|
|
|
177
|
+// ->update([
|
|
|
178
|
+// 'status' => 1,
|
|
|
179
|
+// 'settlement_time' => date('Y-m-d H:i:s')
|
|
|
180
|
+// ]);
|
|
|
181
|
+// }
|
|
|
182
|
+//
|
|
|
183
|
+//
|
|
|
184
|
+// // 结算京豆
|
|
|
185
|
+// $user_sign_jingdou_list = Db::name('user_sign_jingdou')
|
|
|
186
|
+// ->where('status', -1)
|
|
|
187
|
+// ->where('order_id', $online['order_id'])
|
|
|
188
|
+// ->whereIn('type', [1, 2])
|
|
|
189
|
+// ->select()
|
|
|
190
|
+// ->toArray();
|
|
|
191
|
+// foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
|
|
|
192
|
+// // 修改京豆
|
|
|
193
|
+// Db::name('user')
|
|
|
194
|
+// ->where('uid', $user_sign_jingdou['uid'])
|
|
|
195
|
+// ->inc('jingdou', (float)$user_sign_jingdou['number'])
|
|
|
196
|
+// ->update();
|
|
|
197
|
+// Db::name('user_sign_jingdou')
|
|
|
198
|
+// ->where('status', -1)
|
|
|
199
|
+// ->where('id', $user_sign_jingdou['id'])
|
|
|
200
|
+// ->update([
|
|
|
201
|
+// 'status' => 1,
|
|
|
202
|
+// 'settlement_time' => date('Y-m-d H:i:s')
|
|
|
203
|
+// ]);
|
|
|
204
|
+// }
|
|
|
205
|
+//
|
|
|
206
|
+//
|
|
|
207
|
+//
|
|
|
208
|
+// // 结算复购金
|
|
|
209
|
+// $user_sign_fugou_list = Db::name('user_sign_fugou')
|
|
|
210
|
+// ->where('status', -1)
|
|
|
211
|
+// ->where('order_id', $online['order_id'])
|
|
|
212
|
+// ->whereIn('type', [1, 2])
|
|
|
213
|
+// ->select()
|
|
|
214
|
+// ->toArray();
|
|
|
215
|
+// foreach ($user_sign_fugou_list as $user_sign_fugou) {
|
|
|
216
|
+// // 修改复购金
|
|
|
217
|
+// Db::name('user')
|
|
|
218
|
+// ->where('uid', $user_sign_fugou['uid'])
|
|
|
219
|
+// ->inc('fugou', (float)$user_sign_fugou['number'])
|
|
|
220
|
+// ->update();
|
|
|
221
|
+// Db::name('user_sign_fugou')
|
|
|
222
|
+// ->where('status', -1)
|
|
|
223
|
+// ->where('id', $user_sign_fugou['id'])
|
|
|
224
|
+// ->update([
|
|
|
225
|
+// 'status' => 1,
|
|
|
226
|
+// 'settlement_time' => date('Y-m-d H:i:s')
|
|
|
227
|
+// ]);
|
|
|
228
|
+// }
|
|
|
229
|
+//
|
|
|
230
|
+//
|
|
|
231
|
+// // 结算贡献值
|
|
|
232
|
+// $user_sign_gongxian_list = Db::name('user_sign_gongxian')
|
|
|
233
|
+// ->where('status', -1)
|
|
|
234
|
+// ->where('order_id', $online['order_id'])
|
|
|
235
|
+// ->whereIn('type', [1, 2])
|
|
|
236
|
+// ->select()
|
|
|
237
|
+// ->toArray();
|
|
|
238
|
+// foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
|
|
|
239
|
+// // 修改贡献值
|
|
|
240
|
+// Db::name('user')
|
|
|
241
|
+// ->where('uid', $user_sign_gongxian['uid'])
|
|
|
242
|
+// ->inc('contribute', (float)$user_sign_gongxian['number'])
|
|
|
243
|
+// ->update();
|
|
|
244
|
+// Db::name('user_sign_gongxian')
|
|
|
245
|
+// ->where('status', -1)
|
|
|
246
|
+// ->where('id', $user_sign_gongxian['id'])
|
|
|
247
|
+// ->update([
|
|
|
248
|
+// 'status' => 1,
|
|
|
249
|
+// 'settlement_time' => date('Y-m-d H:i:s')
|
|
|
250
|
+// ]);
|
|
|
251
|
+// }
|
|
|
252
|
+//
|
|
|
253
|
+//
|
|
|
254
|
+// // 结算佣金
|
|
|
255
|
+// $user_bill_list = Db::name('user_bill')
|
|
|
256
|
+// ->where('status', 0)
|
|
|
257
|
+// ->where('commission_type','<>', 5)
|
|
|
258
|
+// ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
|
|
|
259
|
+// ->select()
|
|
|
260
|
+// ->toArray();
|
|
|
261
|
+// foreach ($user_bill_list as $user_bill) {
|
|
|
262
|
+// if ($user_bill['commission_type'] != 5) {
|
|
|
263
|
+// if (in_array($user_bill['commission_type'], [7,12,19])) {
|
|
|
264
|
+// Db::name("merchant")
|
|
|
265
|
+// ->where("mer_id", $user_bill['mer_id'])
|
|
|
266
|
+// ->inc('brokerage_price', (float)$user_bill['number'])
|
|
|
267
|
+// ->update();
|
|
|
268
|
+// } else {
|
|
|
269
|
+// Db::name('user')
|
|
|
270
|
+// ->where('uid', $user_bill['uid'])
|
|
|
271
|
+// ->inc('brokerage_price', (float)$user_bill['number'])
|
|
|
272
|
+// ->update();
|
|
|
273
|
+// }
|
|
|
274
|
+// }
|
|
|
275
|
+// if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
|
|
|
276
|
+// } else {
|
|
|
277
|
+// // 虚拟支付的养老金不修改不结算
|
|
|
278
|
+// Db::name('user_bill')
|
|
|
279
|
+// ->where('status', 0)
|
|
|
280
|
+// ->where('bill_id', $user_bill['bill_id'])
|
|
|
281
|
+// ->update([
|
|
|
282
|
+// 'status' => 1,
|
|
|
283
|
+// 'take_time' => time()
|
|
|
284
|
+// ]);
|
|
|
285
|
+// }
|
|
|
286
|
+// if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
|
|
|
287
|
+// } else {
|
|
|
288
|
+// // 虚拟支付的养老金不修改不结算
|
|
|
289
|
+// Db::name('user_bill')
|
|
|
290
|
+// ->where('status', 0)
|
|
|
291
|
+// ->where('bill_id', $user_bill['bill_id'])
|
|
|
292
|
+// ->update([
|
|
|
293
|
+// 'status' => 1,
|
|
|
294
|
+// 'take_time' => time()
|
|
|
295
|
+// ]);
|
|
|
296
|
+// }
|
|
|
297
|
+// }
|
|
|
298
|
+// //按角色结算
|
|
|
299
|
+// $StoreOrderRepository->close_order($online['order_id']);
|
|
|
300
|
+// });
|
|
|
301
|
+// }
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+}
|