PackageServer.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\server\package;
  3. use app\admin\model\Package;
  4. use app\admin\model\PackageGoods;
  5. use app\admin\model\PackageOrder;
  6. use app\admin\model\PackageOrderDetail;
  7. use app\admin\model\SystemAdmin;
  8. use app\admin\model\SystemMenu;
  9. use app\admin\model\SystemRole;
  10. class PackageServer
  11. {
  12. /**
  13. * Notes:获取角色列表
  14. * @param string $keywords
  15. * @param int $page
  16. * @param int $limit
  17. * @return array
  18. * User: QJF
  19. * Date: 2022/9/17
  20. */
  21. public static function getPackageList(int $page, int $limit, $keywords)
  22. {
  23. [$list, $count] = Package::getPackageList($page, $limit, $keywords);
  24. return compact('list', 'page', 'limit', 'count');
  25. }
  26. /**
  27. * Notes: 添加权益包
  28. * @param array $param
  29. * @return int
  30. * User: QJF
  31. * Date: 2022/9/17
  32. */
  33. public static function insertPackage(array $param)
  34. {
  35. SystemRole::affairBegin();
  36. try {
  37. $param['package_create_time'] = time();
  38. $param['package_update_time'] = time();
  39. $result = Package::insertGetId($param);
  40. if (!empty($result)){
  41. SystemRole::affairCommit();
  42. return $result;
  43. }
  44. throw new \Exception('操作失败!');
  45. }catch (\Exception $exception){
  46. SystemRole::affairRollback();
  47. throw new \Exception($exception->getMessage(), 500);
  48. }
  49. }
  50. /**
  51. * Notes:修改角色
  52. * @param array $param
  53. * @return int
  54. * User: QJF
  55. * Date: 2022/9/19
  56. */
  57. public static function updatePackage($param)
  58. {
  59. SystemRole::affairBegin();
  60. try {
  61. $where = [];
  62. $where['package_id'] = $param['package_id'];
  63. $param['package_update_time'] = time();
  64. $result = Package::where($where)->update($param);
  65. if ($result !== false){
  66. SystemRole::affairCommit();
  67. return true;
  68. }
  69. throw new \Exception('操作失败!');
  70. }catch (\Exception $exception){
  71. SystemRole::affairRollback();
  72. throw new \Exception($exception->getMessage(), 500);
  73. }
  74. }
  75. /**
  76. * Notes:任务
  77. * @param int $role_id
  78. * @return int
  79. * User: QJF
  80. * Date: 2022/9/19
  81. */
  82. public static function delPackage($package_id)
  83. {
  84. SystemRole::affairBegin();
  85. try {
  86. $where = [];
  87. $where['package_id'] = $package_id;
  88. $data['package_is_del'] = 1;
  89. $data['package_update_time'] = time();
  90. $result = Package::where($where)->update($data);
  91. if (!empty($result)){
  92. SystemRole::affairCommit();
  93. return true;
  94. }else{
  95. return false;
  96. }
  97. }catch (\Exception $exception){
  98. SystemRole::affairRollback();
  99. throw new \Exception($exception->getMessage(), 500);
  100. }
  101. }
  102. /**
  103. * Notes:获取权益包详情
  104. * @param int $package_id
  105. * @return int
  106. * User: QJF
  107. * Date: 2022/9/19
  108. */
  109. public static function infoPackage($package_id)
  110. {
  111. SystemRole::affairBegin();
  112. try {
  113. $where = [];
  114. $where['package_id'] = $package_id;
  115. $result = Package::where($where)->first();
  116. if (!empty($result)){
  117. SystemRole::affairCommit();
  118. return $result;
  119. }else{
  120. return false;
  121. }
  122. }catch (\Exception $exception){
  123. SystemRole::affairRollback();
  124. throw new \Exception($exception->getMessage(), 500);
  125. }
  126. }
  127. /**
  128. * Notes:赠送会员权益包
  129. * @param $user_id
  130. * @param $package_id
  131. * @return int
  132. * @throws \Exception
  133. * User: yym
  134. * Date: 2022/11/21
  135. */
  136. public static function givePackage($user_id, $package_id)
  137. {
  138. try {
  139. $package_info = Package::getInfo($package_id);
  140. if(empty($package_info) || $package_info['package_status'] == Package::PACKAGE_LOWER_SHELF || $package_info['package_delete_time'] > 0)
  141. {
  142. throw new \Exception('产品已下架或已删除');
  143. }
  144. if(!isset($package_info['goods']) || empty($package_info['goods']))
  145. {
  146. throw new \Exception('套餐包暂未关联产品');
  147. }
  148. $time = time();
  149. $_order = array(
  150. 'order_dno' => createOrderSn(16),
  151. 'order_user_id' => $user_id,
  152. 'order_package_id' => $package_id,
  153. 'order_pay_type' => 1,
  154. 'order_place_time' => $time,
  155. 'order_create_time' => $time,
  156. 'order_pay_status' => PackageOrder::PAY_STATUS_YES,
  157. 'order_pay_time' => $time,
  158. 'order_end_time' => $time + 86400 * 365
  159. );
  160. $_order_detail = array();
  161. $order_price = 0;
  162. foreach ($package_info['goods'] as $k => $item)
  163. {
  164. $order_detail = array(
  165. 'detail_goods_id' => $item['goods_id'],
  166. 'detail_user_id' => $user_id,
  167. 'detail_goods_name' => $item['goods_name'],
  168. 'detail_img' => $item['goods_img'],
  169. 'detail_nape' => $item['goods_nape'],
  170. 'detail_equity' => $item['goods_equity'],
  171. 'detail_price' => $item['goods_price'],
  172. 'detail_create_time' => $time,
  173. 'detail_update_time' => $time
  174. );
  175. $_order_detail[] = $order_detail;
  176. $order_price += $item['goods_price'];
  177. }
  178. $_order['order_price'] = $order_price;
  179. //生成主订单
  180. $order_id = PackageOrder::insertData($_order);
  181. if($order_id)
  182. {
  183. foreach ($_order_detail as $row)
  184. {
  185. $row['detail_order_id'] = $order_id;
  186. PackageOrderDetail::insertData($row);
  187. }
  188. return $order_id;
  189. }
  190. throw new \Exception('生成订单失败!');
  191. }catch (\Exception $exception){
  192. throw new \Exception($exception->getMessage(), 500);
  193. }
  194. }
  195. }