StoreOrderTakeServices.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\dao\order\StoreOrderDao;
  13. use app\jobs\order\AutoTakeOrderJob;
  14. use app\jobs\notice\SmsAdminJob;
  15. use app\services\BaseServices;
  16. use app\services\message\service\StoreServiceServices;
  17. use app\services\message\sms\SmsSendServices;
  18. use app\services\user\member\MemberCardServices;
  19. use app\services\user\UserBillServices;
  20. use app\services\user\UserBrokerageServices;
  21. use app\services\user\level\UserLevelServices;
  22. use app\services\user\UserServices;
  23. use think\exception\ValidateException;
  24. use think\facade\Log;
  25. /**
  26. * 订单收货
  27. * Class StoreOrderTakeServices
  28. * @package app\services\order
  29. * @mixin StoreOrderDao
  30. */
  31. class StoreOrderTakeServices extends BaseServices
  32. {
  33. /**
  34. * 构造方法
  35. * StoreOrderTakeServices constructor.
  36. * @param StoreOrderDao $dao
  37. */
  38. public function __construct(StoreOrderDao $dao)
  39. {
  40. $this->dao = $dao;
  41. }
  42. /**
  43. * 小程序订单服务收货
  44. * @param $order_id
  45. * @return bool
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function miniOrderTakeOrder($order_id)
  51. {
  52. $orderArr = explode('_', $order_id);
  53. if (count($orderArr) == 2) {
  54. $order_id = $orderArr[1] ?? $order_id;
  55. }
  56. //查找订单信息
  57. $order = $this->dao->getOne(['order_id' => $order_id]);
  58. if (!$order) {
  59. return true;
  60. }
  61. if ($order['pid'] == -1) { // 有子订单
  62. // 查找待收货的子订单
  63. $son_order_list = $this->dao->getSubOrderNotSendList((int)$order['id']);
  64. foreach ($son_order_list as $son_order) {
  65. $this->takeOrder($son_order['order_id'], $son_order['uid']);
  66. }
  67. } else {
  68. $this->takeOrder($order_id, $order['uid']);
  69. }
  70. return true;
  71. }
  72. /**
  73. * 用户订单收货
  74. * @param $uni
  75. * @param $uid
  76. * @return bool
  77. */
  78. public function takeOrder(string $uni, int $uid)
  79. {
  80. $order = $this->dao->getUserOrderDetail($uni, $uid);
  81. if (!$order) {
  82. throw new ValidateException('订单不存在!');
  83. }
  84. /** @var StoreOrderServices $orderServices */
  85. $orderServices = app()->make(StoreOrderServices::class);
  86. $order = $orderServices->tidyOrder($order);
  87. if ($order['_status']['_type'] != 2) {
  88. throw new ValidateException('订单状态错误!');
  89. }
  90. //存在拆分发货 需要分开收货
  91. if ($this->dao->count(['pid' => $order['id']])) {
  92. throw new ValidateException('拆分发货,请去订单详情中包裹确认收货');
  93. }
  94. if ($order['type'] != 8) {
  95. $order->status = 2;
  96. } else {
  97. $order->status = 3;
  98. }
  99. /** @var StoreOrderStatusServices $statusService */
  100. $statusService = app()->make(StoreOrderStatusServices::class);
  101. $res = $order->save() && $statusService->save([
  102. 'oid' => $order['id'],
  103. 'change_type' => 'user_take_delivery',
  104. 'change_message' => '用户已收货',
  105. 'change_time' => time()
  106. ]);
  107. $res = $res && $this->storeProductOrderUserTakeDelivery($order);
  108. if (!$res) {
  109. throw new ValidateException('收货失败');
  110. }
  111. //核销订单 修改订单商品核销状态
  112. if ($order['shipping_type'] == 2 || (in_array($order['shipping_type'], [1, 3]) && $order['delivery_type'] == 'send')) {
  113. //修改原来订单商品信息
  114. $cartData['is_writeoff'] = 1;
  115. $cartData['write_surplus_times'] = 0;
  116. /** @var StoreOrderCartInfoServices $cartInfoServices */
  117. $cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
  118. $cartInfoServices->update(['oid' => $order['id']], $cartData);
  119. }
  120. return $order;
  121. }
  122. /**
  123. * 订单确认收货
  124. * @param $order
  125. * @return bool
  126. */
  127. public function storeProductOrderUserTakeDelivery($order, bool $isTran = true)
  128. {
  129. $res = true;
  130. //获取购物车内的商品标题
  131. /** @var StoreOrderCartInfoServices $orderInfoServices */
  132. $orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
  133. $storeName = $orderInfoServices->getCarIdByProductTitle((int)$order['id']);
  134. $storeTitle = substrUTf8($storeName, 20, 'UTF-8', '');
  135. if ($order['uid']) {
  136. /** @var UserServices $userServices */
  137. $userServices = app()->make(UserServices::class);
  138. $userInfo = $userServices->get((int)$order['uid']);
  139. $res = $this->transaction(function () use ($order, $userInfo, $storeTitle) {
  140. //赠送积分
  141. $res1 = $this->gainUserIntegral($order, $userInfo, $storeTitle);
  142. //返佣
  143. $res2 = $this->backOrderBrokerage($order, $userInfo);
  144. //经验
  145. $res3 = $this->gainUserExp($order, $userInfo);
  146. if (!($res1 && $res2 && $res3)) {
  147. throw new ValidateException('收货失败!');
  148. }
  149. return true;
  150. }, $isTran);
  151. }
  152. if ($res) {
  153. //订单收货事件
  154. event('order.take', [$order, $storeTitle]);
  155. return true;
  156. } else {
  157. return false;
  158. }
  159. }
  160. /**
  161. * 赠送积分
  162. * @param $order
  163. * @param $userInfo
  164. * @param $storeTitle
  165. * @return bool
  166. */
  167. public function gainUserIntegral($order, $userInfo, $storeTitle)
  168. {
  169. $res2 = true;
  170. if (!$userInfo) {
  171. return true;
  172. }
  173. // 营销产品送积分
  174. if (!isset($order['type']) || in_array($order['type'], [1, 2, 3, 5, 8])) {
  175. return true;
  176. }
  177. /** @var UserBillServices $userBillServices */
  178. $userBillServices = app()->make(UserBillServices::class);
  179. $balance = $userInfo['integral'];
  180. if ($order['gain_integral'] > 0) {
  181. $balance = bcadd((string)$balance, (string)$order['gain_integral']);
  182. $res2 = false != $userBillServices->income('pay_give_integral', $order['uid'], (int)$order['gain_integral'], (int)$balance, $order['id']);
  183. }
  184. $order_integral = 0;
  185. $res3 = true;
  186. $order_give_integral = sys_config('order_give_integral');
  187. if ($order['pay_price'] && $order_give_integral) {
  188. //会员消费返积分翻倍
  189. if ($userInfo['is_money_level'] > 0) {
  190. //看是否开启消费返积分翻倍奖励
  191. /** @var MemberCardServices $memberCardService */
  192. $memberCardService = app()->make(MemberCardServices::class);
  193. $integral_rule_number = $memberCardService->isOpenMemberCardCache('integral');
  194. if ($integral_rule_number) {
  195. $order_integral = bcmul((string)$order['pay_price'], (string)$integral_rule_number, 2);
  196. }
  197. }
  198. $order_integral = bcmul((string)$order_give_integral, (string)($order_integral ? $order_integral : $order['pay_price']), 0);
  199. $balance = bcadd((string)$balance, (string)$order_integral);
  200. $res3 = false != $userBillServices->income('order_give_integral', $order['uid'], (int)$order_integral, (int)$balance, $order['id']);
  201. }
  202. $give_integral = $order_integral + $order['gain_integral'];
  203. if ($give_integral > 0) {
  204. $integral = $userInfo['integral'] + $give_integral;
  205. $userInfo->integral = $integral;
  206. $res1 = false != $userInfo->save();
  207. $res = $res1 && $res2 && $res3;
  208. //发送消息
  209. event('notice.notice', [['order' => $order, 'storeTitle' => $storeTitle, 'give_integral' => $give_integral, 'integral' => $integral], 'integral_accout']);
  210. return $res;
  211. }
  212. return true;
  213. }
  214. /**
  215. * 一级返佣
  216. * @param $orderInfo
  217. * @param $userInfo
  218. * @return bool
  219. */
  220. public function backOrderBrokerage($orderInfo, $userInfo)
  221. {
  222. // 当前订单|用户不存在 直接返回
  223. if (!$orderInfo || !$userInfo) {
  224. return true;
  225. }
  226. //商城分销功能是否开启 0关闭1开启
  227. if (!sys_config('brokerage_func_status')) return true;
  228. // 营销产品不返佣金
  229. if (!isset($orderInfo['type']) || in_array($orderInfo['type'], [1, 2, 3, 5, 8])) {
  230. return true;
  231. }
  232. //绑定失效
  233. if (isset($orderInfo['spread_uid']) && $orderInfo['spread_uid'] == -1) {
  234. return true;
  235. }
  236. //是否开启自购返佣
  237. $isSelfBrokerage = sys_config('is_self_brokerage', 0);
  238. if (!isset($orderInfo['spread_uid']) || !$orderInfo['spread_uid']) {//兼容之前订单表没有spread_uid情况
  239. //没开启自购返佣 没有上级 或者 当用用户上级时自己 直接返回
  240. if (!$isSelfBrokerage && (!$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid'])) {
  241. return true;
  242. }
  243. $one_spread_uid = $isSelfBrokerage ? $userInfo['uid'] : $userInfo['spread_uid'];
  244. } else {
  245. $one_spread_uid = $orderInfo['spread_uid'];
  246. }
  247. $one_spread_uid = (int)$one_spread_uid;
  248. //冻结时间
  249. $broken_time = intval(sys_config('extract_time'));
  250. $frozen_time = time() + $broken_time * 86400;
  251. //订单中取出
  252. $brokeragePrice = $orderInfo['one_brokerage'] ?? 0;
  253. // 一级返佣金额小于等于0
  254. if ($brokeragePrice <= 0) {//直接二级返佣
  255. return $this->backOrderBrokerageTwo($orderInfo, $userInfo, $isSelfBrokerage, $frozen_time);
  256. }
  257. // 获取上级推广员信息
  258. /** @var UserServices $userServices */
  259. $userServices = app()->make(UserServices::class);
  260. $spreadPrice = $userServices->value(['uid' => $one_spread_uid], 'brokerage_price');
  261. // 上级推广员返佣之后的金额
  262. $balance = bcadd($spreadPrice, $brokeragePrice, 2);
  263. // 添加佣金记录
  264. /** @var UserBrokerageServices $userBrokerageServices */
  265. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  266. //自购返佣 || 上级
  267. $type = $one_spread_uid == $orderInfo['uid'] ? 'get_self_brokerage' : 'get_brokerage';
  268. $res1 = $userBrokerageServices->income($type, $one_spread_uid, [
  269. 'nickname' => $userInfo['nickname'],
  270. 'pay_price' => floatval($orderInfo['pay_price']),
  271. 'number' => floatval($brokeragePrice),
  272. 'frozen_time' => $frozen_time
  273. ], $balance, $orderInfo['id']);
  274. // 添加用户佣金
  275. $res2 = $userServices->bcInc($one_spread_uid, 'brokerage_price', $brokeragePrice, 'uid');
  276. //给上级发送获得佣金的模板消息
  277. $this->sendBackOrderBrokerage($orderInfo, $one_spread_uid, $brokeragePrice);
  278. // 一级返佣成功 跳转二级返佣
  279. $res = $res1 && $res2 && $this->backOrderBrokerageTwo($orderInfo, $userInfo, $isSelfBrokerage, $frozen_time);
  280. return $res;
  281. }
  282. /**
  283. * 二级推广返佣
  284. * @param $orderInfo
  285. * @param $userInfo
  286. * @param int $isSelfbrokerage
  287. * @param int $frozenTime
  288. * @return bool
  289. */
  290. public function backOrderBrokerageTwo($orderInfo, $userInfo, $isSelfbrokerage = 0, $frozenTime = 0)
  291. {
  292. //绑定失效
  293. if (isset($orderInfo['spread_two_uid']) && $orderInfo['spread_two_uid'] == -1) {
  294. return true;
  295. }
  296. /** @var UserServices $userServices */
  297. $userServices = app()->make(UserServices::class);
  298. if (isset($orderInfo['spread_two_uid']) && $orderInfo['spread_two_uid']) {
  299. $spread_two_uid = $orderInfo['spread_two_uid'];
  300. } else {
  301. // 获取上推广人
  302. $userInfoTwo = $userServices->get((int)$userInfo['spread_uid']);
  303. // 订单|上级推广人不存在 直接返回
  304. if (!$orderInfo || !$userInfoTwo) {
  305. return true;
  306. }
  307. //没开启自购返佣 或者 上推广人没有上级 或者 当用用户上上级时自己 直接返回
  308. if (!$isSelfbrokerage && (!$userInfoTwo['spread_uid'] || $userInfoTwo['spread_uid'] == $orderInfo['uid'])) {
  309. return true;
  310. }
  311. $spread_two_uid = $isSelfbrokerage ? $userInfoTwo['uid'] : $userInfoTwo['spread_uid'];
  312. }
  313. $spread_two_uid = (int)$spread_two_uid;
  314. //订单中取出
  315. $brokeragePrice = $orderInfo['two_brokerage'] ?? 0;
  316. // 返佣金额小于等于0 直接返回不返佣金
  317. if ($brokeragePrice <= 0) {
  318. return true;
  319. }
  320. // 获取上上级推广员信息
  321. $spreadPrice = $userServices->value(['uid' => $spread_two_uid], 'brokerage_price');
  322. // 获取上上级推广员返佣之后余额
  323. $balance = bcadd($spreadPrice, $brokeragePrice, 2);
  324. // 添加佣金记录
  325. /** @var UserBrokerageServices $userBrokerageServices */
  326. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  327. $res1 = $userBrokerageServices->income('get_two_brokerage', $spread_two_uid, [
  328. 'nickname' => $userInfo['nickname'],
  329. 'pay_price' => floatval($orderInfo['pay_price']),
  330. 'number' => floatval($brokeragePrice),
  331. 'frozen_time' => $frozenTime
  332. ], $balance, $orderInfo['id']);
  333. // 添加用户佣金
  334. $res2 = $userServices->bcInc($spread_two_uid, 'brokerage_price', $brokeragePrice, 'uid');
  335. //给上级发送获得佣金的模板消息
  336. $this->sendBackOrderBrokerage($orderInfo, $spread_two_uid, $brokeragePrice);
  337. return $res1 && $res2;
  338. }
  339. /**
  340. * 佣金到账发送模板消息
  341. * @param $orderInfo
  342. * @param $spread_uid
  343. * @param $brokeragePrice
  344. */
  345. public function sendBackOrderBrokerage($orderInfo, $spread_uid, $brokeragePrice, string $type = 'order')
  346. {
  347. /** @var UserServices $userServices */
  348. $userServices = app()->make(UserServices::class);
  349. $user = $userServices->getUserInfo($spread_uid, 'phone,user_type');
  350. if ($type == 'order') {
  351. /** @var StoreOrderCartInfoServices $storeOrderCartInfoService */
  352. $storeOrderCartInfoService = app()->make(StoreOrderCartInfoServices::class);
  353. $cartInfo = $storeOrderCartInfoService->getOrderCartInfo($orderInfo['id']);
  354. if ($cartInfo) {
  355. $cartInfo = array_column($cartInfo, 'cart_info');
  356. $goodsPrice = 0;
  357. $goodsName = "";
  358. foreach ($cartInfo as $k => $v) {
  359. $goodsName .= $v['productInfo']['store_name'];
  360. $price = $v['productInfo']['attrInfo']['price'] ?? $v['productInfo']['price'] ?? 0;
  361. $goodsPrice = bcadd((string)$goodsPrice, (string)$price, 2);
  362. }
  363. }
  364. } else {
  365. $goodsName = '推广用户获取佣金';
  366. $goodsPrice = $brokeragePrice;
  367. }
  368. //提醒推送
  369. event('notice.notice', [['spread_uid' => $spread_uid, 'phone' => $user['phone'], 'userType' => $user['user_type'], 'brokeragePrice' => $brokeragePrice, 'goodsName' => $goodsName, 'goodsPrice' => $goodsPrice, 'add_time' => $orderInfo['add_time'] ?? time()], 'order_brokerage']);
  370. return true;
  371. }
  372. /**
  373. * 发送短信
  374. * @param $order
  375. * @param $storeTitle
  376. */
  377. public function smsSend($order, $storeTitle)
  378. {
  379. /** @var SmsSendServices $smsServices */
  380. $smsServices = app()->make(SmsSendServices::class);
  381. $switch = (bool)sys_config('confirm_take_over_switch');
  382. //模板变量
  383. $store_name = $storeTitle;
  384. $order_id = $order['order_id'];
  385. $smsServices->send($switch, $order['user_phone'], compact('store_name', 'order_id'), 'TAKE_DELIVERY_CODE');
  386. }
  387. /**
  388. * 发送确认收货管理员短信
  389. * @param $order
  390. */
  391. public function smsSendTake($order)
  392. {
  393. $switch = (bool)sys_config('admin_confirm_take_over_switch');
  394. /** @var StoreServiceServices $services */
  395. $services = app()->make(StoreServiceServices::class);
  396. $adminList = $services->getStoreServiceOrderNotice();
  397. SmsAdminJob::dispatchDo('sendAdminConfirmTakeOver', [$switch, $adminList, $order]);
  398. return true;
  399. }
  400. /**
  401. * 赠送经验
  402. * @param $order
  403. * @param $userInfo
  404. * @return bool
  405. */
  406. public function gainUserExp($order, $userInfo)
  407. {
  408. if (!$userInfo) {
  409. return true;
  410. }
  411. //用户等级是否开启
  412. if (!sys_config('member_func_status', 1)) {
  413. return true;
  414. }
  415. /** @var UserBillServices $userBillServices */
  416. $userBillServices = app()->make(UserBillServices::class);
  417. $order_exp = 0;
  418. $res3 = true;
  419. $order_give_exp = sys_config('order_give_exp');
  420. $balance = $userInfo['exp'];
  421. if ($order['pay_price'] && $order_give_exp) {
  422. $order_exp = bcmul($order_give_exp, (string)$order['pay_price'], 2);
  423. $balance = bcadd((string)$balance, (string)$order_exp, 2);
  424. $res3 = false != $userBillServices->income('order_give_exp', $order['uid'], $order_exp, $balance, $order['id']);
  425. }
  426. $res = true;
  427. if ($order_exp > 0) {
  428. $userInfo->exp = $balance;
  429. $res1 = false != $userInfo->save();
  430. $res = $res1 && $res3;
  431. }
  432. /** @var UserLevelServices $levelServices */
  433. $levelServices = app()->make(UserLevelServices::class);
  434. $levelServices->detection((int)$order['uid']);
  435. return $res;
  436. }
  437. /**
  438. * 加入队列
  439. * @param array $where
  440. * @param int $count
  441. * @param int $maxLimit
  442. * @return bool
  443. */
  444. public function batchJoinJobs(array $where, int $count, int $maxLimit)
  445. {
  446. $page = ceil($count / $maxLimit);
  447. for ($i = 1; $i <= $page; $i++) {
  448. AutoTakeOrderJob::dispatch([$where, $i, $maxLimit]);
  449. }
  450. return true;
  451. }
  452. /**
  453. * 执行自动收货
  454. * @param array $where
  455. * @param int $page
  456. * @param int $maxLimit
  457. * @return bool
  458. */
  459. public function runAutoTakeOrder(array $where, int $page = 0, int $maxLimit = 0)
  460. {
  461. /** @var StoreOrderStoreOrderStatusServices $service */
  462. $service = app()->make(StoreOrderStoreOrderStatusServices::class);
  463. $orderList = $service->getOrderIds($where, $page, $maxLimit);
  464. /** @var StoreOrderRefundServices $storeOrderRefundServices */
  465. $storeOrderRefundServices = app()->make(StoreOrderRefundServices::class);
  466. foreach ($orderList as $order) {
  467. if ($order['status'] == 2) {
  468. continue;
  469. }
  470. if ($order['paid'] == 1 && $order['status'] == 1) {
  471. $data['status'] = 2;
  472. } else if ($order['pay_type'] == 'offline') {
  473. $data['status'] = 2;
  474. } else {
  475. continue;
  476. }
  477. if ($storeOrderRefundServices->count(['store_order_id' => $order['id'], 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 1])) {
  478. continue;
  479. }
  480. try {
  481. /** @var StoreOrderStatusServices $statusService */
  482. $statusService = app()->make(StoreOrderStatusServices::class);
  483. $res = $this->dao->update($order['id'], $data) && $statusService->save([
  484. 'oid' => $order['id'],
  485. 'change_type' => 'take_delivery',
  486. 'change_message' => '已收货[自动收货]',
  487. 'change_time' => time()
  488. ]);
  489. $res = $res && $this->storeProductOrderUserTakeDelivery($order);
  490. if (!$res) {
  491. throw new ValidateException('订单号' . $order['order_id'] . '自动收货失败');
  492. }
  493. } catch (\Throwable $e) {
  494. Log::error('自动收货失败,失败原因:' . $e->getMessage());
  495. }
  496. }
  497. return true;
  498. }
  499. /**
  500. * 自动收货
  501. * @return bool
  502. */
  503. public function autoTakeOrder()
  504. {
  505. //7天前时间戳
  506. $systemDeliveryTime = (int)sys_config('system_delivery_time', 0);
  507. //0为取消自动收货功能
  508. if ($systemDeliveryTime == 0) {
  509. return true;
  510. }
  511. $sevenDay = strtotime(date('Y-m-d H:i:s', strtotime('-' . $systemDeliveryTime . ' day')));
  512. /** @var StoreOrderStoreOrderStatusServices $service */
  513. $service = app()->make(StoreOrderStoreOrderStatusServices::class);
  514. $where = [
  515. 'change_time' => $sevenDay,
  516. 'is_del' => 0,
  517. 'paid' => 1,
  518. 'status' => 1,
  519. 'change_type' => ['delivery_goods', 'delivery_fictitious', 'delivery', 'city_delivery']
  520. ];
  521. $maxLimit = 20;
  522. $count = $service->getOrderCount($where);
  523. if ($count > $maxLimit) {
  524. return $this->batchJoinJobs($where, $count, $maxLimit);
  525. }
  526. return $this->runAutoTakeOrder($where);
  527. }
  528. }