Storejoinin.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * 店铺入住模型
  4. */
  5. namespace app\common\model;
  6. use think\facade\Db;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 数据层模型
  16. */
  17. class Storejoinin extends BaseModel
  18. {
  19. public $page_info;
  20. /**
  21. * 读取列表
  22. * @access public
  23. * @author csdeshang
  24. * @param array $condition 条件
  25. * @param int $pagesize 分页
  26. * @param string $order 排序
  27. * @param string $field 字段
  28. * @return array
  29. */
  30. public function getStorejoininList($condition, $pagesize = '', $order = '', $field = '*')
  31. {
  32. if ($pagesize) {
  33. $result = Db::name('storejoinin')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  34. $this->page_info = $result;
  35. return $result->items();
  36. } else {
  37. $result = Db::name('storejoinin')->field($field)->where($condition)->order($order)->select()->toArray();
  38. return $result;
  39. }
  40. }
  41. /**
  42. * 店铺入住数量
  43. * @access public
  44. * @author csdeshang
  45. * @param array $condition 条件
  46. * @return int
  47. */
  48. public function getStorejoininCount($condition)
  49. {
  50. return Db::name('storejoinin')->where($condition)->count();
  51. }
  52. /**
  53. * 读取单条记录
  54. * @access public
  55. * @author csdeshang
  56. * @param array $condition 条件
  57. * @return array
  58. */
  59. public function getOneStorejoinin($condition)
  60. {
  61. $result = Db::name('storejoinin')->where($condition)->find();
  62. return $result;
  63. }
  64. /**
  65. * 判断是否存在
  66. * @access public
  67. * @author csdeshang
  68. * @param type $condition 条件
  69. * @return boolean
  70. */
  71. public function isStorejoininExist($condition)
  72. {
  73. $result = $this->getOneStorejoinin($condition);
  74. if (empty($result)) {
  75. return FALSE;
  76. } else {
  77. return TRUE;
  78. }
  79. }
  80. /**
  81. * 增加
  82. * @access public
  83. * @author csdeshang
  84. * @param type $data 数据
  85. * @return type
  86. */
  87. public function addStorejoinin($data)
  88. {
  89. return Db::name('storejoinin')->insert($data);
  90. }
  91. /**
  92. * 更新
  93. * @access public
  94. * @author csdeshang
  95. * @param type $update 数据
  96. * @param type $condition 条件
  97. * @return type
  98. */
  99. public function editStorejoinin($update, $condition)
  100. {
  101. return Db::name('storejoinin')->where($condition)->update($update);
  102. }
  103. /**
  104. * 删除
  105. * @access public
  106. * @author csdeshang
  107. * @param type $condition 条件
  108. * @return type
  109. */
  110. public function delStorejoinin($condition)
  111. {
  112. return Db::name('storejoinin')->where($condition)->delete();
  113. }
  114. /**
  115. * 充值卡支付
  116. * 如果充值卡足够就单独支付了该订单,如果不足就暂时冻结,等API支付成功了再彻底扣除
  117. */
  118. public function rcbPay($order_info, $input, $buyer_info)
  119. {
  120. $available_rcb_amount = floatval($buyer_info['available_rc_balance']);
  121. if ($available_rcb_amount <= 0)
  122. return $order_info;
  123. $predeposit_model = model('predeposit');
  124. $order_amount = round($order_info['paying_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'], 2);
  125. $data_pd = array();
  126. $data_pd['member_id'] = $buyer_info['member_id'];
  127. $data_pd['member_name'] = $buyer_info['member_name'];
  128. $data_pd['amount'] = $order_amount;
  129. $data_pd['order_sn'] = $order_info['pay_sn'];
  130. if ($available_rcb_amount >= $order_amount) {
  131. // 预存款立即支付,订单支付完成
  132. $predeposit_model->changeRcb('storejoinin_pay', $data_pd);
  133. $available_rcb_amount -= $order_amount;
  134. //支付被冻结的充值卡
  135. $rcb_amount = isset($order_info['rcb_amount']) ? floatval($order_info['rcb_amount']) : 0;
  136. if ($rcb_amount > 0) {
  137. $data_pd = array();
  138. $data_pd['member_id'] = $buyer_info['member_id'];
  139. $data_pd['member_name'] = $buyer_info['member_name'];
  140. $data_pd['amount'] = $rcb_amount;
  141. $data_pd['order_sn'] = $order_info['pay_sn'];
  142. $predeposit_model->changeRcb('storejoinin_comb_pay', $data_pd);
  143. }
  144. $store_model = model('store');
  145. $store_model->setStoreOpen($order_info, array('joinin_state' => STORE_JOIN_STATE_FINAL, 'payment_code' => 'predeposit'));
  146. // 订单状态 置为已支付
  147. $order_info['rcb_amount'] = round($order_info['rcb_amount'] + $order_amount, 2);
  148. } else {
  149. //暂冻结预存款,后面还需要 API彻底完成支付
  150. $data_pd['amount'] = $available_rcb_amount;
  151. $predeposit_model->changeRcb('storejoinin_freeze', $data_pd);
  152. //预存款支付金额保存到订单
  153. $data_order = array();
  154. $order_info['rcb_amount'] = $data_order['rcb_amount'] = round($order_info['rcb_amount'] + $available_rcb_amount, 2);
  155. $result = $this->editStorejoinin($data_order, array('member_id' => $order_info['member_id']));
  156. if (!$result) {
  157. throw new \think\Exception('订单更新失败', 10006);
  158. }
  159. }
  160. return $order_info;
  161. }
  162. /**
  163. * 预存款支付 主要处理
  164. * 如果预存款足够就单独支付了该订单,如果不足就暂时冻结,等API支付成功了再彻底扣除
  165. */
  166. public function pdPay($order_info, $input, $buyer_info)
  167. {
  168. if ($order_info['joinin_state'] == STORE_JOIN_STATE_FINAL)
  169. return $order_info;
  170. $available_pd_amount = floatval($buyer_info['available_predeposit']);
  171. if ($available_pd_amount <= 0)
  172. return $order_info;
  173. $predeposit_model = model('predeposit');
  174. $order_amount = round($order_info['paying_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'], 2);
  175. $data_pd = array();
  176. $data_pd['member_id'] = $buyer_info['member_id'];
  177. $data_pd['member_name'] = $buyer_info['member_name'];
  178. $data_pd['amount'] = $order_amount;
  179. $data_pd['order_sn'] = $order_info['pay_sn'];
  180. if ($available_pd_amount >= $order_amount) {
  181. //预存款立即支付,订单支付完成
  182. $predeposit_model->changePd('storejoinin_pay', $data_pd);
  183. $available_pd_amount -= $order_amount;
  184. //下单,支付被冻结的充值卡
  185. $pd_amount = floatval($order_info['rcb_amount']);
  186. if ($pd_amount > 0) {
  187. $data_pd = array();
  188. $data_pd['member_id'] = $buyer_info['member_id'];
  189. $data_pd['member_name'] = $buyer_info['member_name'];
  190. $data_pd['amount'] = $pd_amount;
  191. $data_pd['order_sn'] = $order_info['pay_sn'];
  192. $predeposit_model->changeRcb('order_comb_pay', $data_pd);
  193. }
  194. //支付被冻结的预存款
  195. $pd_amount = isset($order_info['pd_amount']) ? floatval($order_info['pd_amount']) : 0;
  196. if ($pd_amount > 0) {
  197. $data_pd = array();
  198. $data_pd['member_id'] = $buyer_info['member_id'];
  199. $data_pd['member_name'] = $buyer_info['member_name'];
  200. $data_pd['amount'] = $pd_amount;
  201. $data_pd['order_sn'] = $order_info['pay_sn'];
  202. $predeposit_model->changePd('storejoinin_comb_pay', $data_pd);
  203. }
  204. $store_model = model('store');
  205. $store_model->setStoreOpen($order_info, array('joinin_state' => STORE_JOIN_STATE_FINAL, 'payment_code' => 'predeposit'));
  206. // 订单状态 置为已支付
  207. $order_info['pd_amount'] = round($order_info['pd_amount'] + $order_amount, 2);
  208. } else {
  209. //暂冻结预存款,后面还需要 API彻底完成支付
  210. $data_pd['amount'] = $available_pd_amount;
  211. $predeposit_model->changePd('storejoinin_freeze', $data_pd);
  212. //预存款支付金额保存到订单
  213. $data_order = array();
  214. $order_info['pd_amount'] = $data_order['pd_amount'] = round($order_info['pd_amount'] + $available_pd_amount, 2);
  215. $result = $this->editStorejoinin($data_order, array('member_id' => $order_info['member_id']));
  216. if (!$result) {
  217. throw new \think\Exception('订单更新失败', 10006);
  218. }
  219. }
  220. return $order_info;
  221. }
  222. }