PurchaseClearController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\clear\classes\ClearClass;
  4. use bizHd\purchase\classes\PurchaseClearClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use Yii;
  8. class PurchaseClearController extends BaseController
  9. {
  10. //供货商向基地供货商结账生成订单 ssh 20220523
  11. public function actionCreateOrder()
  12. {
  13. $post = Yii::$app->request->post();
  14. $current = time();
  15. $list = ClearClass::getAllByCondition([
  16. 'clearStyle' => dict::getDict('clearStyle', 'gys2KmGys'),
  17. 'shopId' => $this->shopId,
  18. 'status' => PurchaseClearClass::STATUS_AWAIT_PAY
  19. ], null, '*', null, true);
  20. if (!empty($list)) {
  21. foreach ($list as $item) {
  22. $deadline = $item->deadline;
  23. $deadTime = strtotime($deadline);
  24. if ($current > $deadTime) {
  25. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  26. $item->save();
  27. } else {
  28. util::fail('还有待付款的结账单');
  29. }
  30. }
  31. }
  32. if (getenv('YII_ENV') == 'production') {
  33. //小向花卉采购的结账确认,有多处,关键词ghs_cg_clear_confirm
  34. if (in_array($this->mainId, [23390, 24516])) {
  35. if (!in_array($this->adminId, [24655])) {
  36. util::fail('不能操作哈');
  37. }
  38. }
  39. //花大苪 洋桔梗,只有叶荷姐才能销账
  40. if (in_array($this->shopId, [16070])) {
  41. if (!in_array($this->adminId, [9303, 4])) {
  42. util::fail('暂无权限');
  43. }
  44. }
  45. } else {
  46. if (in_array($this->shopId, [36523])) {
  47. // if (!in_array($this->adminId, [919])) {
  48. // util::fail('不能操作...');
  49. // }
  50. }
  51. }
  52. $post['sjId'] = $this->sjId;
  53. $post['shopId'] = $this->shopId;
  54. $post['clearStyle'] = dict::getDict('clearStyle', 'gys2KmGys');
  55. $post['customShopAdminId'] = $this->shopAdminId;
  56. $post['customShopId'] = $this->shopId ?? 0;
  57. $shopAdmin = $this->shopAdmin;
  58. $shopAdminName = $shopAdmin['name'] ?? '';
  59. $post['customShopAdminName'] = $shopAdminName;
  60. $connection = Yii::$app->db;
  61. $transaction = $connection->beginTransaction();
  62. try {
  63. $respond = ClearClass::addOrder($post);
  64. $transaction->commit();
  65. util::success($respond);
  66. } catch (\Exception $e) {
  67. $transaction->rollBack();
  68. Yii::info("下单失败原因:" . $e->getMessage());
  69. util::fail('下单失败');
  70. }
  71. }
  72. }