Storejoinin.php 9.0 KB

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