Consult.php 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','=',$infoNo];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $role=$this->checkRole();
  59. if(!empty($role['write'])){
  60. $where[]=["b.createrid","in",$role['write']];
  61. }
  62. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  63. ->count();
  64. $total = ceil($count / $size);
  65. $page = $page >= $total ? $total : $page;
  66. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  67. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  68. $data=[];
  69. foreach ($list as $value){
  70. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  71. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  72. true):[];
  73. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  74. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  75. $value['khname']="";
  76. if($value['khNo']!==""){
  77. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  78. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  79. }
  80. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  81. $data[]=$value;
  82. }
  83. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  84. }
  85. public function info(){
  86. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  87. if($id==""){
  88. return error_show(1002,"咨询单编号不能为空");
  89. }
  90. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  91. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  92. $fo['can']=$in;
  93. if(empty($fo)){
  94. return error_show(1002,"未找到咨询单编号");
  95. }else{
  96. return app_show(0,"获取成功",$fo);
  97. }
  98. }
  99. public function del(){
  100. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  101. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  102. if($de==false){
  103. return error_show(1002,'咨询单信息未找到');
  104. }
  105. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  106. if($dell){
  107. return error_show(0,"删除成功");
  108. }else
  109. return error_show(1002,"删除失败");
  110. }
  111. public function create(){
  112. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  113. if($is_project===""){
  114. return error_show(1002,"参数is_project不能为空");
  115. }
  116. if($is_project==1){
  117. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  118. if($projectNo===""){
  119. return error_show(1002,"参数projectNo不能为空");
  120. }
  121. }
  122. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  123. if($khNo===""){
  124. return error_show(1002,"参数khNo不能为空");
  125. }
  126. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  127. if($companyNo===""){
  128. return error_show(1002,"参数companyNo不能为空");
  129. }
  130. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  131. if($endtime===""){
  132. return error_show(1002,"参数endtime不能为空");
  133. }
  134. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  135. "";
  136. if($platform_code===""){
  137. return error_show(1002,"参数platform_code不能为空");
  138. }
  139. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  140. if($ladder==""){
  141. return error_show(1005,"参数ladder不能为空");
  142. }
  143. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  144. if($token==''){
  145. return error_show(105,"参数token不能为空");
  146. }
  147. $user =GetUserInfo($token);
  148. if(empty($user)||$user['code']!=0){
  149. return error_show(102,"用户数据不存在");
  150. }
  151. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  152. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  153. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  154. $zxNo=makeNo("ZX");
  155. Db::startTrans();
  156. try{
  157. $data=[
  158. "zxNo"=>$zxNo,
  159. "createrid"=>$createrid,
  160. "creater"=>$creater,
  161. "is_project"=>$is_project,
  162. "projectNo"=>isset($projectNo) ? $projectNo:"",
  163. "khNo"=>$khNo,
  164. "companyNo"=>$companyNo,
  165. "endtime"=>$endtime,
  166. "salesman"=>$creater,
  167. "platform_code"=>$platform_code,
  168. "saleid"=>$createrid,
  169. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  170. "status"=>0,
  171. "is_del"=>0,
  172. "addtime"=>date("Y-m-d H:i:s"),
  173. "updatetime"=>date("Y-m-d H:i:s"),
  174. ];
  175. $zx = Db::name("consult_order")->insert($data);
  176. if($zx){
  177. foreach ($ladder as $value){
  178. $infoNo=makeNo("IF");
  179. $specinfo=[];
  180. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  181. foreach ($value["specinfo"] as $v){
  182. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  183. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  184. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  185. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  186. $specinfo[]=$v;
  187. }
  188. }
  189. $info=[
  190. "infoNo"=>$infoNo,
  191. "zxNo"=>$zxNo,
  192. "spuCode"=>"",
  193. "good_name"=>$value['good_name'],
  194. "good_img"=>$value['good_img'],
  195. "cat_id"=>$value['cat_id'],
  196. "unit"=>$value['unit'],
  197. "brand_id"=>$value['brand_id'],
  198. "arrival_time"=>$value['arrival_time'],
  199. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  200. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  201. "is_addrs"=>$value['is_addrs'],
  202. "is_custom"=>$value['is_custom'],
  203. "metal_id"=>$value['metal_id'],
  204. "config"=>isset($value['config'])?$value['config']:"",
  205. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  206. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  207. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  208. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  209. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  210. "budget_price"=>$value['budget_price'],
  211. "num"=>$value['num'],
  212. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  213. "use_desc"=>$value['use_desc'],
  214. "remark"=>$value['remark'],
  215. "status"=>1,
  216. "is_del"=>0,
  217. "addtime"=>date("Y-m-d H:i:s"),
  218. "updatetime"=>date("Y-m-d H:i:s"),
  219. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  220. ];
  221. $up = Db::name("consult_info")->insert($info);
  222. if(!$up){
  223. Db::rollback();
  224. return error_show(1004,'添加失败');
  225. }else{
  226. //修改状态,添加待办
  227. ActionLog::logAdd($this->post['token'], [
  228. "order_code" => $infoNo,//咨询单详情编号
  229. "status" => 1,//这里的status是之前的值
  230. "action_remark" => '',//备注
  231. "action_type" => "create"//新建create,编辑edit,更改状态status
  232. ], "ZXD", 1, $info);
  233. ProcessOrder::AddProcess($this->post['token'], [
  234. "order_type" => 'ZXD',
  235. "order_code" => $infoNo,//咨询单详情编号
  236. "order_id" => 0,
  237. "order_status" => 1
  238. ]);
  239. }
  240. }
  241. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  242. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  243. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  244. ProcessOrder::AddProcess($this->post['token'],$process);
  245. Db::commit();
  246. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  247. }else{
  248. Db::rollback();
  249. return error_show(1004,"新建失败");
  250. }
  251. }catch (\Exception $e){
  252. Db::rollback();
  253. return error_show(1003,$e->getMessage());
  254. }
  255. }
  256. public function zxinfo(){
  257. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  258. if($infoNo==""){
  259. return error_show(1004,"参数infoNo不能为空");
  260. }
  261. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  262. if($zxinfo==false){
  263. return error_show(1004,"未找到信息数据");
  264. }
  265. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  266. if($zxorder==false){
  267. return error_show(1004,"未找到咨询信息数据");
  268. }
  269. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  270. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  271. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  272. $zxinfo['khname']="";
  273. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  274. $zxinfo['khNo']="";
  275. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  276. $zxinfo['brand']="";
  277. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  278. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  279. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  280. $zxinfo['company']="";
  281. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  282. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  283. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  284. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  285. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  286. $zxinfo['project_name']="";
  287. $zxinfo['budget_total']="";
  288. $zxinfo['departinfo']=[];
  289. $zxinfo['unit_name']="";
  290. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  291. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  292. if($zxorder['khNo']!==""){
  293. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  294. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  295. $zxinfo['khNo']= $zxorder['khNo'];
  296. }
  297. if($zxinfo['unit']!==""){
  298. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  299. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  300. }
  301. if($zxinfo['brand_id']!==""){
  302. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  303. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  304. }
  305. if($zxorder['companyNo']!==""){
  306. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  307. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  308. }
  309. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  310. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  311. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  312. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  313. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  314. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  315. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  316. }
  317. if($zxorder['depart']>0){
  318. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  319. }
  320. if($zxorder['platform_code']>0){
  321. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  322. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  323. }
  324. return app_show(0,"获取成功",$zxinfo);
  325. }
  326. public function zxedit(){
  327. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  328. if($infoNo==""){
  329. return error_show(1004,"参数infoNo不能为空");
  330. }
  331. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  332. if($zxinfo==false){
  333. return error_show(1004,"未找到信息数据");
  334. }
  335. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  336. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  337. if($good_name==""){
  338. return error_show(1003,"参数good_name不能为空");
  339. }
  340. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  341. if($good_img==""){
  342. return error_show(1003,"参数good_img不能为空");
  343. }
  344. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  345. if($cat_id==""){
  346. return error_show(1003,"参数cat_id不能为空");
  347. }
  348. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  349. if($unit==""){
  350. return error_show(1003,"参数unit不能为空");
  351. }
  352. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  353. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  354. if($arrival_time==""){
  355. return error_show(1003,"参数arrival_time不能为空");
  356. }
  357. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  358. if($specin==""){
  359. return error_show(1003,"参数specinfo不能为空");
  360. }
  361. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  362. // if($cost_desc==""){
  363. // return error_show(1003,"参数cost_desc不能为空");
  364. // }
  365. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  366. if($is_addrs===""){
  367. return error_show(1003,"参数is_addrs不能为空");
  368. }
  369. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  370. if($is_custom===""){
  371. return error_show(1003,"参数is_custom不能为空");
  372. }
  373. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  374. if($metal_id===""){
  375. return error_show(1003,"参数metal_id不能为空");
  376. }
  377. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  378. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  379. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  380. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  381. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  382. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  383. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  384. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  385. if($num===""){
  386. return error_show(1003,"参数num不能为空");
  387. }
  388. if($budget_price===""){
  389. return error_show(1003,"参数budget_price不能为空");
  390. }
  391. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  392. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  393. if($use_desc==""){
  394. return error_show(1003,"参数use_desc不能为空");
  395. }
  396. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  397. if($remark==""){
  398. return error_show(1003,"参数remark不能为空");
  399. }
  400. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  401. if($endtime==""){
  402. return error_show(1003,"参数endtime不能为空");
  403. }
  404. if($metal_id!=0){
  405. if($config==""){
  406. return error_show(1003,"参数config不能为空");
  407. }
  408. if($other_config==""){
  409. return error_show(1003,"参数other_config不能为空");
  410. }
  411. if($specs_weight===""){
  412. return error_show(1003,"参数specs_weight不能为空");
  413. }
  414. if($gold_price===""){
  415. return error_show(1003,"参数gold_price不能为空");
  416. }
  417. }
  418. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  419. if($token==''){
  420. return error_show(102,"参数token不能为空");
  421. }
  422. $user =GetUserInfo($token);
  423. if(empty($user)||$user['code']!=0){
  424. return error_show(105,"用户数据不存在");
  425. }
  426. $specinfo=[];
  427. foreach ($specin as $v){
  428. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  429. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  430. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  431. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  432. $specinfo[]=$v;
  433. }
  434. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  435. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  436. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  437. Db::startTrans();
  438. try{
  439. $innew =makeNo("IF");
  440. $info=[
  441. "infoNo"=>$innew,
  442. "zxNo"=>$zxinfo['zxNo'],
  443. "spuCode"=>"",
  444. "good_name"=>$good_name,
  445. "good_img"=>$good_img,
  446. "cat_id"=>$cat_id,
  447. "unit"=>$unit,
  448. "brand_id"=>$brand_id,
  449. "arrival_time"=>$arrival_time,
  450. "specinfo"=>json_encode($specinfo),
  451. // "color"=>$color,
  452. // "material"=>$material,
  453. "cost_desc"=>$cost_desc,
  454. "is_addrs"=>$is_addrs,
  455. "is_custom"=>$is_custom,
  456. "metal_id"=>$metal_id,
  457. "config"=>$config,
  458. "other_config"=>$other_config,
  459. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  460. "gold_price"=>$gold_price===""? 0 : $gold_price,
  461. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  462. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  463. "budget_price"=>$budget_price,
  464. "num"=>$num,
  465. "pgNo"=>$pgNo,
  466. "use_desc"=>$use_desc,
  467. "remark"=>$remark,
  468. "status"=>1,
  469. "is_del"=>0,
  470. "addtime"=>date("Y-m-d H:i:s"),
  471. "updatetime"=>date("Y-m-d H:i:s"),
  472. 'bargain_status'=>1,
  473. 'enclosure_file'=>$enclosure_file
  474. ];
  475. $up = Db::name("consult_info")->insert($info);
  476. if($up){
  477. //修改状态,添加待办
  478. ActionLog::logAdd($this->post['token'], [
  479. "order_code" => $innew,//咨询单详情编号
  480. "status" => 1,//这里的status是之前的值
  481. "action_remark" => '',//备注
  482. "action_type" => "create"//新建create,编辑edit,更改状态status
  483. ], "ZXD", 1, $info);
  484. ProcessOrder::AddProcess($this->post['token'], [
  485. "order_type" => 'ZXD',
  486. "order_code" => $innew,//咨询单详情编号
  487. "order_id" => 0,
  488. "order_status" => 1
  489. ]);
  490. if (!empty($bidlist)){
  491. foreach ($bidlist as $value){
  492. unset($value['id']);
  493. $value['infoNo']=$innew;
  494. $value['bidNo']=makeNo("BD");
  495. $value['spuCode']=makeNo("SKU");
  496. $value['status'] =0;
  497. $value['updatetime'] =date("Y-m-d H:i:s");
  498. $in = Db::name("consult_bids")->insert($value);
  499. if($in==false){
  500. Db::rollback();
  501. return error_show(1004,"反馈商品新建失败");
  502. }
  503. }
  504. }
  505. $zxinfo["bargain_status"] =1;
  506. $zxinfo["bargain_code"] =$innew;
  507. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  508. $bar=Db::name("consult_info")->save($zxinfo);
  509. if($bar==false){
  510. Db::rollback();
  511. return error_show(1004,"反馈商品更新失败");
  512. }else{
  513. //修改状态,添加待办
  514. ActionLog::logAdd($this->post['token'], [
  515. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  516. "status" => $zxinfo['status'],//这里的status是之前的值
  517. "action_remark" => '',//备注
  518. "action_type" => "edit"//新建create,编辑edit,更改状态status
  519. ], "ZXD", $zxinfo['status'], $zxinfo);
  520. // 并没有修改状态
  521. // ProcessOrder::AddProcess($this->post['token'], [
  522. // "order_type" => 'ZXD',
  523. // "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  524. // "order_id" => $zxinfo['id'],
  525. // "order_status" => $zxinfo['status']
  526. // ]);
  527. }
  528. //更新consule_order记录
  529. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  530. Db::commit();
  531. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  532. }
  533. }catch (\Exception $e){
  534. Db::rollback();
  535. return error_show(1004,$e->getMessage());
  536. }
  537. }
  538. //** 发布竞标任务 */
  539. public function bargain(){
  540. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  541. if($infoNo==""){
  542. return error_show(1004,"参数infoNo不能为空");
  543. }
  544. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  545. if($zxinfo==false){
  546. return error_show(1004,"未找到信息数据");
  547. }
  548. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  549. if($status===""){
  550. return error_show(1004,"参数status不能为空");
  551. }
  552. if($status==1&&$zxinfo['status']>1){
  553. $zxinfo['bargain_num']=+1;
  554. }
  555. $old_zxinfo_status = $zxinfo['status'];
  556. $zxinfo['status']=$status;
  557. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  558. $up = Db::name("consult_info")->save($zxinfo);
  559. if($up){
  560. //修改状态,添加待办
  561. ActionLog::logAdd($this->post['token'], [
  562. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  563. "status" => $old_zxinfo_status,//这里的status是之前的值
  564. "action_remark" => '',//备注
  565. "action_type" => "status"//新建create,编辑edit,更改状态status
  566. ], "ZXD", $zxinfo['status'], $zxinfo);
  567. ProcessOrder::AddProcess($this->post['token'], [
  568. "order_type" => 'ZXD',
  569. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  570. "order_id" => $zxinfo['id'],
  571. "order_status" => $zxinfo['status']
  572. ]);
  573. return app_show(0,"状态更新成功");
  574. }else{
  575. return error_show(1003,"状态更新失败");
  576. }
  577. }
  578. public function feadback(){
  579. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  580. if($infoNo==""){
  581. return error_show(1002,"参数infoNo不能为空");
  582. }
  583. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  584. if($zxinfo==false){
  585. return error_show(1003,"未找到信息数据");
  586. }
  587. if($zxinfo['status']!=1){
  588. return error_show(1004,"任务未进行");
  589. }
  590. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  591. if($zx==false){
  592. return error_show(1003,"未找咨询信息数据");
  593. }
  594. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  595. if($pname==""){
  596. return error_show(1002,"参数pname不能为空");
  597. }
  598. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  599. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  600. if($cat_id==""){
  601. return error_show(1002,"参数cat_id不能为空");
  602. }
  603. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  604. if($specin==""){
  605. return error_show(1003,"参数specinfo不能为空");
  606. }
  607. $specinfo=[];
  608. foreach ($specin as $v){
  609. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  610. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  611. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  612. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  613. $specinfo[]=$v;
  614. }
  615. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  616. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  617. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  618. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  619. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  620. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  621. :"";
  622. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  623. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  624. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  625. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  626. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  627. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  628. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  629. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  630. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  631. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  632. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  633. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  634. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  635. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  636. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  637. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  638. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  639. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  640. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  641. if($nake_fee==="" ){
  642. return error_show(1004,"参数nake_fee不能为空");
  643. }
  644. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  645. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  646. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  647. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  648. if($token==''){
  649. return error_show(1002,"参数token不能为空");
  650. }
  651. $user =GetUserInfo($token);
  652. if(empty($user)||$user['code']!=0){
  653. return error_show(1005,"用户数据不存在");
  654. }
  655. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  656. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  657. $bidNo=makeNo("BD");
  658. $spucode=makeNo("SKU");
  659. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  660. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  661. //部分参数的大小校验
  662. $vali = Validate::rule([
  663. 'expire_day|有效时长'=>'require|elt:214748364',
  664. 'delivery_day|物流时长'=>'require|elt:214748364',
  665. 'work_day|生产工期'=>'require|elt:214748364',
  666. 'weight|总重量'=>'require|max:10',
  667. ]);
  668. $temp = [
  669. 'expire_day'=>$expire_day,
  670. 'delivery_day'=>$delivery_day,
  671. 'work_day'=>$work_day,
  672. 'weight'=>$weight,
  673. ];
  674. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  675. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  676. $cat_top_list = made($cat_id);
  677. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  678. if ($is_gold_price == 1 && $cat_top_id == 6) {
  679. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  680. ->find();
  681. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  682. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  683. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  684. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  685. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  686. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  687. $saleprice = $total_fee/ (1 - $budget);
  688. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  689. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  690. }else{
  691. if($nake_fee){
  692. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  693. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  694. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  695. }else{
  696. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  697. (1 - $budget);
  698. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  699. }
  700. }
  701. $data=[
  702. "bidNo"=>$bidNo,
  703. "infoNo"=>$infoNo,
  704. "zxNo"=>$zxinfo['zxNo'],
  705. "spuCode"=>$spucode,
  706. "good_name"=>$pname,
  707. "brand_id"=>$brandid,
  708. "cat_id"=>$cat_id,
  709. "specinfo"=>json_encode($specinfo),
  710. "unit_id"=>$unit_id,
  711. "cost_desc"=>$cost_desc,
  712. "work_day"=>$work_day,
  713. "delivery_day"=>$delivery_day,
  714. "good_img"=>$good_img,
  715. "expire_day"=>$expire_day,
  716. "origin_place"=>$origin_place,
  717. "supplierNo"=>$supplierNo,
  718. "pay_way"=>$pay_way,
  719. "tax"=>$tax,
  720. "send_way"=>$send_way,
  721. "metal_id"=>$metal_id,
  722. "is_gold_price"=>$is_gold_price,
  723. "config"=>$config,
  724. "other_config"=>$other_config,
  725. "weight"=>$weight,
  726. "good_weight"=>$good_weight,
  727. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  728. "is_diff"=>$is_diff,
  729. "demo_fee"=>$demo_fee,
  730. "delivery_fee"=>$delivery_fee,
  731. "open_fee"=>$open_fee,
  732. "pakge_fee"=>$pakge_fee,
  733. "nake_fee"=>$nake_fee,
  734. "mark_fee"=>$mark_fee,
  735. "cert_fee"=>$cert_fee,
  736. "cost_fee"=>$cost_fee,
  737. "total_fee"=>$total_fee,
  738. "supply_area"=>$supply_area,
  739. "remark"=>$remark,
  740. "sale_price"=>$saleprice,
  741. "sale_cost_fee"=>$sale_cost_fee,
  742. "origin_cost_fee"=>$sale_cost_fee,
  743. "origin_price"=>$saleprice,
  744. "createrid"=>$createrid,
  745. "creater"=>$creater,
  746. "status"=>$zxinfo['status']==1 ?1 :2,
  747. "is_del"=>0,
  748. "addtime"=>date("Y-m-d H:i:s"),
  749. "updatetime"=>date("Y-m-d H:i:s")
  750. ];
  751. Db::startTrans();
  752. try{
  753. $insert= Db::name("consult_bids")->insert($data);
  754. if($insert){
  755. // $data=[
  756. // "spuCode"=>$spucode,
  757. // "good_name"=>$pname,
  758. // "brand_id"=>$brandid,
  759. // "good_unit"=>$unit_id,
  760. // "good_type"=>0,
  761. // "moq"=>1,
  762. // "customized"=>$work_day,
  763. // "tax"=>$tax,
  764. // "supplierNo"=>$supplierNo,
  765. // "is_auth"=>0,
  766. // "craft_desc"=>$cost_desc,
  767. // "good_remark"=>$remark,
  768. // "good_img"=>$good_img,
  769. // "good_thumb_img"=>"",
  770. // "good_info_img"=>"",
  771. // "status"=>1,
  772. // "is_del"=>0,
  773. // "createrid"=>$createrid,
  774. // "creater"=>$creater,
  775. // "addtime"=>date("Y-m-d H:i:s"),
  776. // "updatetime"=>date("Y-m-d H:i:s")
  777. // ];
  778. // $good = Db::name("good_zixun")->insert($data);
  779. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  780. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  781. if($projectinfo==false){
  782. Db::rollback();
  783. return error_show(1006,"未找到项目信息");
  784. }
  785. $temp=[];
  786. $temp['spuCode']=$spucode;
  787. $temp['skuCode']="";
  788. $temp['pgNo']=$zxinfo['pgNo'];
  789. $temp['projectNo']=$zx['projectNo'];
  790. $temp['good_name']=$pname;
  791. $temp['good_type']=$projectinfo['good_type'];
  792. $temp['data_source']=2;
  793. $temp['cat_id']=$cat_id;
  794. $temp['budget_price']=$projectinfo['budget_price'];
  795. $temp['sale_price']=$saleprice;
  796. $temp['origin_price']=$total_fee;
  797. $temp['num']=$zxinfo['num'];
  798. $temp['status']=0;
  799. $temp['is_del']=0;
  800. $temp['creater']=$creater;
  801. $temp['createrid']=$createrid;
  802. $temp['addtime']=date("Y-m-d H:i:s");
  803. $temp['updatetime']=date("Y-m-d H:i:s");
  804. $nu = Db::name("project_feedback")->insert($temp);
  805. if($nu==false){
  806. Db::rollback();
  807. return error_show(1006,"项目反馈失败");
  808. }else{
  809. $old_projectinfo_status = $projectinfo['status'];
  810. $projectinfo['status']=2;
  811. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  812. $up = Db::name("project_info")->save($projectinfo);
  813. if($up){
  814. //修改状态,添加待办,只记录动作
  815. ActionLog::logAdd($this->post['token'], [
  816. "order_code" => $projectinfo['pgNo'],//编码
  817. "status" => $old_projectinfo_status,//这里的status是之前的值
  818. "action_remark" => '',//备注
  819. "action_type" => "status"//新建create,编辑edit,更改状态status
  820. ], "PRO", 2, $projectinfo);
  821. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  822. ->count();
  823. if($count==0){
  824. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  825. if($projetc!=false){
  826. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  827. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  828. if($proc==false){
  829. Db::rollback();
  830. return error_show(1006,"项目反馈失败");
  831. }else{
  832. //修改状态,添加待办
  833. ActionLog::logAdd($this->post['token'], [
  834. "order_code" => $projetc['projectNo'],//项目编码
  835. "status" => 1,//这里的status是之前的值
  836. "action_remark" => '',//备注
  837. "action_type" => "status"//新建create,编辑edit,更改状态status
  838. ], "PRO", 2, $projetc);
  839. ProcessOrder::AddProcess($this->post['token'], [
  840. "order_type" => 'PRO',
  841. "order_code" => $projetc['projectNo'],
  842. "order_id" => $projetc['id'],
  843. "order_status" => 2
  844. ]);
  845. }
  846. }
  847. }
  848. }
  849. }
  850. }
  851. Db::commit();
  852. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  853. }else{
  854. Db::rollback();
  855. return error_show(1006,"反馈失败");
  856. }
  857. }catch (\Exception $e){
  858. Db::rollback();
  859. return error_show(1006,$e->getMessage());
  860. }
  861. }
  862. public function feadinfo(){
  863. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  864. if($bidNo==""){
  865. return error_show(1004,"参数bidNo不能为空");
  866. }
  867. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  868. if($info==false){
  869. return error_show(1004,"未找到商品数据");
  870. }
  871. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  872. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  873. $info['cat_info'] = made($info['cat_id'],[]);
  874. $info['noble_weight'] = $info['good_weight'];
  875. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  876. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  877. if($info['brand_id']!=0){
  878. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  879. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  880. }else{
  881. $info["brand_name"]="";
  882. $info["brand_id"]="";
  883. }
  884. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  885. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  886. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  887. $god=[
  888. "metal_id"=>$info['metal_id'],
  889. "weight"=>$info["good_weight"],
  890. "demo_fee"=>$info["demo_fee"],
  891. "delivery_fee"=>$info["delivery_fee"],
  892. "open_fee"=>$info["open_fee"],
  893. "packing_fee"=>$info["pakge_fee"],
  894. "mark_fee"=>$info["mark_fee"],
  895. "nake_fee"=>$info["nake_fee"],
  896. "cert_fee"=>$info["cert_fee"],
  897. "cost_fee"=>$info["cost_fee"],
  898. "num"=>$bidinfo["num"],
  899. ];
  900. if($info['is_gold_price']==1){
  901. $price = GoldPrice($god, $budget/100);
  902. $info['sale_price'] =round($price,2);
  903. }
  904. $info['specinfo'] = json_decode($info['specinfo'],true);
  905. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  906. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  907. $info['bargain'] =$bargain;
  908. return app_show(0,"获取成功",$info);
  909. }
  910. public function feededit(){
  911. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  912. if($bidNo==""){
  913. return error_show(1002,"参数bidNo不能为空");
  914. }
  915. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  916. if($bidinfo==false){
  917. return error_show(1003,"未找到信息数据");
  918. }
  919. if($bidinfo['status']>=5){
  920. return error_show(1004,"咨询单已确认无法修改");
  921. }
  922. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  923. if($zxinfo==false){
  924. return error_show(1003,"未找到信息数据");
  925. }
  926. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  927. if($zx==false){
  928. return error_show(1003,"未找咨询信息数据");
  929. }
  930. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  931. if($pname==""){
  932. return error_show(1002,"参数pname不能为空");
  933. }
  934. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  935. // if($brandid==""){
  936. // return error_show(1002,"参数brandid不能为空");
  937. // }
  938. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  939. if($cat_id==""){
  940. return error_show(1002,"参数cat_id不能为空");
  941. }
  942. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  943. if($specin==""){
  944. return error_show(1003,"参数specinfo不能为空");
  945. }
  946. $specinfo=[];
  947. foreach ($specin as $v){
  948. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  949. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  950. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  951. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  952. $specinfo[]=$v;
  953. }
  954. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  955. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  956. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  957. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  958. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  959. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  960. :"";
  961. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  962. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  963. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  964. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  965. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  966. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  967. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  968. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  969. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  970. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  971. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  972. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  973. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  974. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  975. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  976. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  977. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  978. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  979. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  980. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  981. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  982. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  983. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  984. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  985. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  986. $cat_top_list = made($cat_id);
  987. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  988. if ($is_gold_price == 1 && $cat_top_id == 6) {
  989. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  990. ->find();
  991. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  992. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  993. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  994. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  995. $saleprice = $total_fee / (1 - $budget);
  996. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  997. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  998. }else{
  999. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1000. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1001. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1002. }
  1003. Db::startTrans();
  1004. try{
  1005. $data=[
  1006. "good_name"=>$pname,
  1007. "brand_id"=>$brandid,
  1008. "cat_id"=>$cat_id,
  1009. "specinfo"=>json_encode($specinfo),
  1010. // "material"=>$material,
  1011. "unit_id"=>$unit_id,
  1012. "cost_desc"=>$cost_desc,
  1013. "work_day"=>$work_day,
  1014. "delivery_day"=>$delivery_day,
  1015. "good_img"=>$good_img,
  1016. "expire_day"=>$expire_day,
  1017. "origin_place"=>$origin_place,
  1018. "supplierNo"=>$supplierNo,
  1019. "pay_way"=>$pay_way,
  1020. "tax"=>$tax,
  1021. "send_way"=>$send_way,
  1022. "metal_id"=>$metal_id,
  1023. "is_gold_price"=>$is_gold_price,
  1024. "config"=>$config,
  1025. "other_config"=>$other_config,
  1026. "weight"=>$weight,
  1027. "good_weight"=>$noble_weight,
  1028. "is_diff"=>$is_diff,
  1029. "demo_fee"=>$demo_fee,
  1030. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1031. "delivery_fee"=>$delivery_fee,
  1032. "open_fee"=>$open_fee,
  1033. "pakge_fee"=>$pakge_fee,
  1034. "nake_fee"=>$nake_fee,
  1035. "mark_fee"=>$mark_fee,
  1036. "cert_fee"=>$cert_fee,
  1037. "cost_fee"=>$cost_fee,
  1038. "sale_cost_fee"=>$sale_cost_fee,
  1039. "total_fee"=>$total_fee,
  1040. "sale_price"=>$saleprice,
  1041. "supply_area"=>$supply_area,
  1042. "remark"=>$remark,
  1043. "updatetime"=>date("Y-m-d H:i:s")
  1044. ];
  1045. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1046. if($insert){
  1047. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1048. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1049. if($projectinfo==false){
  1050. Db::rollback();
  1051. return error_show(1006,"未找到项目信息");
  1052. }
  1053. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1054. if($feed==false){
  1055. Db::rollback();
  1056. return error_show(1006,"未找到项目反馈信息");
  1057. }
  1058. $feed['good_name']=$pname;
  1059. $feed['good_type']=$projectinfo['good_type'];
  1060. $feed['cat_id']=$cat_id;
  1061. $feed['sale_price']=$saleprice;
  1062. $feed['origin_price']=$total_fee;
  1063. $feed['updatetime']=date("Y-m-d H:i:s");
  1064. $temp['updatetime']=date("Y-m-d H:i:s");
  1065. $nu = Db::name("project_feedback")->save($feed);
  1066. if($nu==false){
  1067. Db::rollback();
  1068. return error_show(1006,"项目反馈失败");
  1069. }else{
  1070. $old_projectinfo_status = $projectinfo['status'];
  1071. $projectinfo['status']=2;
  1072. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1073. $up = Db::name("project_info")->save($projectinfo);
  1074. if($up){
  1075. //修改状态,添加待办,只记录动作
  1076. ActionLog::logAdd($this->post['token'], [
  1077. "order_code" => $projectinfo['pgNo'],//编码
  1078. "status" => $old_projectinfo_status,//这里的status是之前的值
  1079. "action_remark" => '',//备注
  1080. "action_type" => "status"//新建create,编辑edit,更改状态status
  1081. ], "PRO", 2, $projectinfo);
  1082. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1083. if ($count == 0) {
  1084. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1085. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1086. if ($project_id) {
  1087. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1088. if ($proc == false) {
  1089. Db::rollback();
  1090. return error_show(1006, "项目反馈失败");
  1091. }else{
  1092. //修改状态,添加待办
  1093. ActionLog::logAdd($this->post['token'], [
  1094. "order_code" => $projectinfo['projectNo'],//项目编码
  1095. "status" => 1,//这里的status是之前的值
  1096. "action_remark" => '',//备注
  1097. "action_type" => "status"//新建create,编辑edit,更改状态status
  1098. ], "PRO", 2, $this->post);
  1099. ProcessOrder::AddProcess($this->post['token'], [
  1100. "order_type" => 'PRO',
  1101. "order_code" => $projectinfo['projectNo'],
  1102. "order_id" => $project_id,
  1103. "order_status" => 2
  1104. ]);
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. Db::commit();
  1112. return app_show(0,"编辑成功");
  1113. }else{
  1114. Db::rollback();
  1115. return error_show(1004,"编辑失败");
  1116. }
  1117. }catch (\Exception $e){
  1118. Db::rollback();
  1119. return error_show(1004,$e->getMessage());
  1120. }
  1121. }
  1122. public function bargain_add(){
  1123. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1124. if($bidNo===""){
  1125. return error_show(1004,"参数bidNo不能为空");
  1126. }
  1127. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1128. if($info==false){
  1129. return error_show(1004,"未找到商品数据");
  1130. }
  1131. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1132. if($consult==false){
  1133. return error_show(1004,"未找到咨询数据");
  1134. }
  1135. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1136. if($bargain_price===""){
  1137. return error_show(1004,"参数bargain_price不能为空");
  1138. }
  1139. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1140. if($info['is_gold_price']==1){
  1141. if($cost_price==""){
  1142. return error_show(1004,"参数cost_price不能为空");
  1143. }
  1144. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1145. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1146. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1147. ->find();
  1148. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1149. }
  1150. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1151. // if($bargain_reason===""){
  1152. // return error_show(1004,"参数bargain_reason不能为空");
  1153. // }
  1154. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1155. if($infos==false){
  1156. return error_show(1004,"未找到商品数据");
  1157. }
  1158. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1159. return error_show(1004,"咨询单招标未结束或已确认商品");
  1160. }
  1161. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1162. if($token==''){
  1163. return error_show(105,"参数token不能为空");
  1164. }
  1165. $user =GetUserInfo($token);
  1166. if(empty($user)||$user['code']!=0){
  1167. return error_show(1002,"用户数据不存在");
  1168. }
  1169. //新增两个字段
  1170. //议价备注
  1171. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1172. //议价原因id
  1173. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1174. if ($result_info_id != '') {
  1175. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1176. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1177. }
  1178. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1179. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1180. $bargainNo =makeNo("BA");
  1181. Db::startTrans();//::todo 金价 毛利计算
  1182. try{
  1183. $data=[
  1184. "bidsNo"=>$bidNo,
  1185. "infoNo"=>$info['infoNo'],
  1186. "zxNo"=>$info['zxNo'],
  1187. "bargainNo"=>$bargainNo,
  1188. "bargain_type"=>1,
  1189. "bargain_reason"=>$bargain_reason,
  1190. "sale_price"=>$info['sale_price'],
  1191. "cost_before_price"=>$info['sale_cost_fee'],
  1192. "cost_after_price"=>$cost_price,
  1193. "before_rate"=>round(($info['sale_price']-$info['total_fee'])/$info['sale_price'],2),
  1194. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1195. "after_price"=>$bargain_price,
  1196. "exam_info"=>"",
  1197. "status"=>0,
  1198. "is_del"=>0,
  1199. "creater"=>$creater,
  1200. "createrid"=>$createrid,
  1201. "addtime"=>date("Y-m-d H:i:s"),
  1202. "updatetime"=>date("Y-m-d H:i:s"),
  1203. 'bargain_remark'=>$bargain_remark,
  1204. 'result_info_id'=>$result_info_id,
  1205. ];
  1206. $int = Db::name("bargain_order")->insert($data);
  1207. if($int){
  1208. $info['status']=3;
  1209. $info['updatetime']=date("Y-m-d H:i:s");
  1210. $up =Db::name("consult_bids")->save($info);
  1211. if($up){
  1212. $old_infos_status = $infos['status'];
  1213. $infos['status']=3;
  1214. $infos['updatetime']=date("Y-m-d H:i:s");
  1215. $ups =Db::name("consult_info")->save($infos);
  1216. if($ups){
  1217. //修改状态,添加待办
  1218. ActionLog::logAdd($this->post['token'], [
  1219. "order_code" => $infos['infoNo'],//咨询单详情编号
  1220. "status" => $old_infos_status,//这里的status是之前的值
  1221. "action_remark" => '',//备注
  1222. "action_type" => "status"//新建create,编辑edit,更改状态status
  1223. ], "ZXD", $infos['status'], $infos);
  1224. ProcessOrder::AddProcess($this->post['token'], [
  1225. "order_type" => 'ZXD',
  1226. "order_code" => $infos['infoNo'],//咨询单详情编号
  1227. "order_id" => $infos['id'],
  1228. "order_status" => $infos['status']
  1229. ]);
  1230. Db::commit();
  1231. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1232. }
  1233. }
  1234. }
  1235. Db::rollback();
  1236. return error_show(1004,"议价单新建失败");
  1237. }catch (\Exception $e){
  1238. Db::rollback();
  1239. return error_show(1004,$e->getMessage());
  1240. }
  1241. }
  1242. //选择商品
  1243. public function bids_check(){
  1244. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1245. if($bidNo===""){
  1246. return error_show(1004,"参数bidNo不能为空");
  1247. }
  1248. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1249. if($info==false){
  1250. return error_show(1004,"未找到商品数据");
  1251. }
  1252. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1253. if($infos==false){
  1254. return error_show(1004,"未找到商品数据");
  1255. }
  1256. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1257. return error_show(1004,"咨询单招标未结束或已确认商品");
  1258. }
  1259. Db::startTrans();
  1260. try {
  1261. $info['status']=6;
  1262. $info['updatetime']=date("Y-m-d H:i:s");
  1263. $bids = Db::name("consult_bids")->save($info);
  1264. if($bids){
  1265. $old_infos_status = $infos['status'];
  1266. $infos['status']=4;
  1267. $infos['updatetime']=date("Y-m-d H:i:s");
  1268. $se = Db::name("consult_info")->save($infos);
  1269. if($se){
  1270. //修改状态,添加待办
  1271. ActionLog::logAdd($this->post['token'], [
  1272. "order_code" => $infos['infoNo'],//咨询单详情编号
  1273. "status" => $old_infos_status,//这里的status是之前的值
  1274. "action_remark" => '',//备注
  1275. "action_type" => "status"//新建create,编辑edit,更改状态status
  1276. ], "ZXD", $infos['status'], $infos);
  1277. ProcessOrder::AddProcess($this->post['token'], [
  1278. "order_type" => 'ZXD',
  1279. "order_code" => $infos['infoNo'],//咨询单详情编号
  1280. "order_id" => $infos['id'],
  1281. "order_status" => $infos['status']
  1282. ]);
  1283. Db::commit();
  1284. return app_show(0,"商品确定成功");
  1285. }
  1286. }
  1287. Db::rollback();
  1288. return error_show(1004,"商品确认失败");
  1289. }catch (\Exception $e){
  1290. Db::rollback();
  1291. return error_show(1004,$e->getMessage());
  1292. }
  1293. }
  1294. //议价审核
  1295. /**
  1296. * status:
  1297. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1298. */
  1299. public function bargain_status(){
  1300. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1301. if($bargainNo===""){
  1302. return error_show(1004,"参数bargainNo不能为空");
  1303. }
  1304. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1305. if($info==false){
  1306. return error_show(1004,"未找到议价数据");
  1307. }
  1308. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1309. if($bids==false){
  1310. return error_show(1004,"未找到商品数据");
  1311. }
  1312. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1313. if($coninfo==false){
  1314. return error_show(1004,"未找到咨询单数据");
  1315. }
  1316. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1317. if($status===''){
  1318. return error_show(1005,"参数status不能为空");
  1319. }
  1320. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1321. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1322. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1323. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1324. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1325. if($bids['is_gold_price']==1){
  1326. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1327. ->find();
  1328. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1329. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1330. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1331. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1332. $saleprice =$total_fe / (1 - $budget);
  1333. $rate_price = $total_fe / (1 - $rate);
  1334. $money_price =$total_fe / (1 - $money_rate);
  1335. $lower_price =$total_fe / (1 - $lower_rate);
  1336. }else{
  1337. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1338. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1339. if($bids['nake_fee']!=0){
  1340. $saleprice = ($total_fe)/ (1 - $budget);
  1341. $rate_price = ($total_fe)/ (1 - $rate);
  1342. $money_price =($total_fe)/ (1 - $money_rate);
  1343. $lower_price = ($total_fe) / (1 - $lower_rate);
  1344. }else{
  1345. $saleprice = $total_fe / (1 - $budget);
  1346. $rate_price =$total_fe/ (1 - $rate);
  1347. $money_price =$total_fe / (1 - $money_rate);
  1348. $lower_price = $total_fe/ (1 - $lower_rate);
  1349. }
  1350. }
  1351. $ra_status = $info['status'];
  1352. if($status==1){
  1353. if($info['status']==0){
  1354. if($info['after_price']<$rate_price){
  1355. $info['status']=2;
  1356. }else{
  1357. $info['status']=1;
  1358. }
  1359. }elseif($info['status']==2){
  1360. $info['status']=4;
  1361. }elseif($info['status']==4||$info['status']==5){
  1362. if($info['after_price']<$money_price){
  1363. $info['status']=7;
  1364. }else{
  1365. $info['status']=6;
  1366. }
  1367. }elseif($info['status']==7){
  1368. $info['lower_price'] =$lower_price;
  1369. if($info['after_price']<$lower_price){
  1370. $info['status']=10;
  1371. }else{
  1372. $info['status']=9;
  1373. }
  1374. }
  1375. }else{
  1376. if($info['status']==0){
  1377. $info['status']=3;
  1378. }elseif($info['status']==2){
  1379. $info['status']=4;
  1380. }elseif($info['status']==4||$info['status']==5){
  1381. $info['status']=8;
  1382. }elseif($info['status']==7){
  1383. $info['lower_price'] =$lower_price;
  1384. $info['status']=11;
  1385. }
  1386. }
  1387. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1388. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1389. if($token==''){
  1390. return error_show(105,"参数token不能为空");
  1391. }
  1392. $user =GetUserInfo($token);
  1393. if(empty($user)||$user['code']!=0){
  1394. return error_show(1002,"用户数据不存在");
  1395. }
  1396. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1397. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1398. Db::startTrans();
  1399. try{
  1400. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1401. $examinfo[]=["status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1402. // $info['status'] =$status;
  1403. $info['remark'] =$remark;
  1404. $info['exam_info']=json_encode($examinfo) ;
  1405. $info['updatetime'] =date("Y-m-d H:i:s");
  1406. $up =Db::name("bargain_order")->save($info);
  1407. if($up){
  1408. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1409. $bids['status']=5;
  1410. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1411. $bids['sale_price']=$info['after_price'];
  1412. if($bids['is_gold_price']==1){
  1413. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1414. // ->find();
  1415. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1416. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1417. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1418. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1419. }
  1420. }
  1421. $bids['updatetime']=date("Y-m-d H:i:s");
  1422. $up =Db::name("consult_bids")->save($bids);
  1423. if($up==false){
  1424. Db::rollback();
  1425. return error_show(1004,"数据更新失败");
  1426. }
  1427. }
  1428. Db::commit();
  1429. return app_show(0,"更新成功");
  1430. }
  1431. }catch (\Exception $e){
  1432. Db::rollback();
  1433. return error_show(1004,$e->getMessage());
  1434. }
  1435. }
  1436. public function bargain_info(){
  1437. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1438. if($bargainNo===""){
  1439. return error_show(1004,"参数bargainNo不能为空");
  1440. }
  1441. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1442. if($info==false){
  1443. return error_show(1004,"未找到议价数据");
  1444. }
  1445. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1446. if($bidinfos==false){
  1447. return error_show(1004,"未找到商品数据");
  1448. }
  1449. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1450. ->find();
  1451. if($consultinfos==false){
  1452. return error_show(1004,"未找到咨询商品数据");
  1453. }
  1454. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1455. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1456. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1457. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1458. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1459. $info['before_rate'] =round($info['before_rate']*100,2);
  1460. $info['after_rate'] = round($info['after_rate']*100,2);
  1461. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1462. if($bidinfos['brand_id']!=0){
  1463. $info['brand_id'] = $bidinfos['brand_id'];
  1464. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1465. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1466. }else{
  1467. $info["brand_name"]="";
  1468. $info["brand_id"]="";
  1469. }
  1470. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1471. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1472. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1473. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1474. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1475. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1476. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1477. $info['budget'] =$budget;
  1478. $god=[
  1479. "metal_id"=>$bidinfos['metal_id'],
  1480. "weight"=>$bidinfos["good_weight"],
  1481. "demo_fee"=>$bidinfos["demo_fee"],
  1482. "delivery_fee"=>$bidinfos["delivery_fee"],
  1483. "open_fee"=>$bidinfos["open_fee"],
  1484. "packing_fee"=>$bidinfos["pakge_fee"],
  1485. "mark_fee"=>$bidinfos["mark_fee"],
  1486. "nake_fee"=>$bidinfos["nake_fee"],
  1487. "cert_fee"=>$bidinfos["cert_fee"],
  1488. "cost_fee"=>$bidinfos["cost_fee"],
  1489. "num"=>$bidinfoe["num"],
  1490. ];
  1491. $info['gold_price']=0;
  1492. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1493. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1494. ->find();
  1495. $info['gold_price'] =$gold['price'];
  1496. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1497. }else{
  1498. if($bidinfos['nake_fee']!=0){
  1499. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1500. }else{
  1501. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1502. }
  1503. }
  1504. $info['cost_desc'] =$bidinfos['cost_desc'];
  1505. $info['work_day'] =$bidinfos['work_day'];
  1506. $info['delivery_day'] =$bidinfos['delivery_day'];
  1507. $info['expire_day'] =$bidinfos['expire_day'];
  1508. $info['origin_place'] =$bidinfos['origin_place'];
  1509. $info['origin_addr'] ="";
  1510. if($bidinfos['origin_place']!=''){
  1511. $code = explode(",",$bidinfos['origin_place']);
  1512. $temp=[];
  1513. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1514. $temp['city_code']=isset($code[1])?$code[1]:"";
  1515. $temp['area_code']=isset($code[2])?$code[2]:"";
  1516. $addr= GetAddr(json_encode($temp));
  1517. $info['origin_addr'] = $addr;
  1518. }
  1519. $info['supplierNo'] =$bidinfos['supplierNo'];
  1520. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1521. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1522. $info['pay_way'] =$bidinfos['pay_way'];
  1523. $info['tax'] =$bidinfos['tax'];
  1524. $info['send_way'] =$bidinfos['send_way'];
  1525. $info['metal_id'] =$bidinfos['metal_id'];
  1526. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1527. $info['config'] =$bidinfos['config'];
  1528. $info['other_config'] =$bidinfos['other_config'];
  1529. $info['weight'] =$bidinfos['weight'];
  1530. $info['good_weight'] =$bidinfos['good_weight'];
  1531. $info['is_diff'] =$bidinfos['is_diff'];
  1532. $info['demo_fee'] =$bidinfos['demo_fee'];
  1533. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1534. $info['open_fee'] =$bidinfos['open_fee'];
  1535. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1536. $info['nake_fee'] =$bidinfos['nake_fee'];
  1537. $info['mark_fee'] =$bidinfos['mark_fee'];
  1538. $info['cert_fee'] =$bidinfos['cert_fee'];
  1539. $info['cost_fee'] =$bidinfos['cost_fee'];
  1540. $info['total_fee'] =$bidinfos['total_fee'];
  1541. $info['supply_area'] =$bidinfos['supply_area'];
  1542. $info['remark'] =$bidinfos['remark'];
  1543. $info['is_addrs'] =$consultinfos['is_addrs'];
  1544. $info['is_custom'] =$consultinfos['is_custom'];
  1545. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1546. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1547. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1548. if($info['status']==7){
  1549. $info['lower_price'] =round($lower_price,2);
  1550. }
  1551. //获取议价原因
  1552. if ($info['result_info_id'] != 0) {
  1553. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1554. } else {
  1555. $info['result_info'] = '';
  1556. }
  1557. return app_show(0,"获取成功",$info);
  1558. }
  1559. public function bidlist(){
  1560. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1561. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1562. $where=[['is_del',"=",0]];
  1563. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1564. if ($zxNo !== "") {
  1565. $where[] = ['zxNo','=',$zxNo];
  1566. }
  1567. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1568. if ($infoNo !== "") {
  1569. $where[] = ['infoNo','=',$infoNo];
  1570. }
  1571. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1572. if ($bidNo !== "") {
  1573. $where[] = ['bidNo','=',$bidNo];
  1574. }
  1575. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1576. if ($pgNo !== "") {
  1577. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1578. $where[] = ['infoNo','in',$bidinfo];
  1579. }
  1580. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1581. if ($bargain_status !== "") {
  1582. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1583. $where[] = ['infoNo','in',$bidinfo];
  1584. }
  1585. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1586. if ($projectNo !== "") {
  1587. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1588. ("zxNo");
  1589. $where[] = ['zxNo','in',$zxlist];
  1590. }
  1591. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1592. if($is_own==1){
  1593. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1594. if($token==""){
  1595. return error_show(101,'token不能为空');
  1596. }
  1597. $apply_id =GetUserInfo($token);
  1598. if(empty($apply_id)||$apply_id['code']!=0){
  1599. return error_show(1002,"申请人数据不存在");
  1600. }
  1601. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1602. $where[]=['createrid',"=",$rm];
  1603. }
  1604. $count = Db::name('consult_bids')->where($where)->count();
  1605. $total = ceil($count / $size);
  1606. $page = $page >= $total ? $total : $page;
  1607. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1608. $data=[];
  1609. foreach ($list as $value){
  1610. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1611. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1612. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1613. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1614. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1615. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1616. if($value['brand_id']!=0){
  1617. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1618. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1619. }else{
  1620. $value["brand_name"]="";
  1621. $value["brand_id"]="";
  1622. }
  1623. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1624. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1625. $god=[
  1626. "metal_id"=>$value['metal_id'],
  1627. "weight"=>$value["good_weight"],
  1628. "demo_fee"=>$value["demo_fee"],
  1629. "delivery_fee"=>$value["delivery_fee"],
  1630. "open_fee"=>$value["open_fee"],
  1631. "packing_fee"=>$value["pakge_fee"],
  1632. "mark_fee"=>$value["mark_fee"],
  1633. "nake_fee"=>$value["nake_fee"],
  1634. "cert_fee"=>$value["cert_fee"],
  1635. "cost_fee"=>$value['status']==5? $value["sale_cost_fee"]: $value["cost_fee"],
  1636. "num"=>$bidinfo["num"],
  1637. ];
  1638. if($value['is_gold_price']==1){
  1639. $price = GoldPrice($god, $budget/100);
  1640. $value['sale_price'] = round($price,2);
  1641. }
  1642. $value['cost_fee'] =$value['origin_cost_fee'];
  1643. $value['specinfo'] = json_decode($value['specinfo'],true);
  1644. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1645. $value['bargain_status']=$bidinfo['bargain_status'];
  1646. //reject驳回原因,status==5表示驳回
  1647. $value['reject']=[];
  1648. if ($value['status'] == 5) {
  1649. $value['reject'] = Db::name('bargain_order')
  1650. ->field('id,remark,status')
  1651. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1652. ->whereIn('status', [5, 6])
  1653. ->find();
  1654. }
  1655. //产地
  1656. if($value['origin_place']!=''){
  1657. $code = explode(",",$value['origin_place']);
  1658. $temp=[];
  1659. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1660. $temp['city_code']=isset($code[1])?$code[1]:"";
  1661. $temp['area_code']=isset($code[2])?$code[2]:"";
  1662. $addr= GetAddr(json_encode($temp));
  1663. $value['origin_addr'] = $addr;
  1664. }
  1665. $data[] = $value;
  1666. }
  1667. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1668. }
  1669. public function feedlist(){
  1670. $where=[['is_del',"=",0]];
  1671. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1672. if ($zxNo !== "") {
  1673. $where[] = ['zxNo','=',$zxNo];
  1674. }
  1675. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1676. if ($infoNo !== "") {
  1677. $where[] = ['infoNo','=',$infoNo];
  1678. }
  1679. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1680. if ($bidNo !== "") {
  1681. $where[] = ['bidNo','=',$bidNo];
  1682. }
  1683. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1684. if ($projectNo !== "") {
  1685. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1686. ("zxNo");
  1687. $where[] = ['zxNo','in',$zxlist];
  1688. }
  1689. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1690. if($token==''){
  1691. return error_show(102,"参数token不能为空");
  1692. }
  1693. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1694. if($is_own==1){
  1695. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1696. if($token==""){
  1697. return error_show(101,'token不能为空');
  1698. }
  1699. $apply_id =GetUserInfo($token);
  1700. if(empty($apply_id)||$apply_id['code']!=0){
  1701. return error_show(1002,"申请人数据不存在");
  1702. }
  1703. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1704. $where[]=['createrid',"=",$rm];
  1705. }
  1706. $list =Db::name('consult_bids')->where($where)->select();
  1707. $data=[];
  1708. foreach ($list as $value){
  1709. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1710. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1711. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1712. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1713. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1714. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1715. if($value['brand_id']!=0){
  1716. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1717. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1718. }else{
  1719. $value["brand_name"]="";
  1720. $value["brand_id"]="";
  1721. }
  1722. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1723. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1724. $god=[
  1725. "metal_id"=>$value['metal_id'],
  1726. "weight"=>$value["good_weight"],
  1727. "demo_fee"=>$value["demo_fee"],
  1728. "delivery_fee"=>$value["delivery_fee"],
  1729. "open_fee"=>$value["open_fee"],
  1730. "packing_fee"=>$value["pakge_fee"],
  1731. "mark_fee"=>$value["mark_fee"],
  1732. "nake_fee"=>$value["nake_fee"],
  1733. "cert_fee"=>$value["cert_fee"],
  1734. "cost_fee"=>$value["cost_fee"],
  1735. "num"=>$bidinfo["num"],
  1736. ];
  1737. if ($value['is_gold_price'] == 1 ) {
  1738. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1739. ->find();
  1740. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1741. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1742. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1743. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1744. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1745. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1746. }else{
  1747. if($value["nake_fee"]){
  1748. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1749. }else{
  1750. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1751. (1 - $budget);
  1752. }
  1753. }
  1754. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1755. $value['specinfo'] = json_decode($value['specinfo'],true);
  1756. $value['bargain_status']=$bidinfo['bargain_status'];
  1757. $data[]=$value;
  1758. }
  1759. return app_show(0,"获取成功",$data);
  1760. }
  1761. public function bragain_list(){
  1762. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1763. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1764. $where=[['is_del',"=",0]];
  1765. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1766. if($bidsNo!=""){
  1767. $where[]=["bidsNo","=",$bidsNo];
  1768. }
  1769. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1770. if ($zxNo !== "") {
  1771. $where[] = ['zxNo','=',$zxNo];
  1772. }
  1773. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1774. if ($infoNo !== "") {
  1775. $where[] = ['infoNo','=',$infoNo];
  1776. }
  1777. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1778. if ($projectNo !== "") {
  1779. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1780. ("zxNo");
  1781. $where[] = ['zxNo','in',$zxlist];
  1782. }
  1783. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1784. if ($pgNo !== "") {
  1785. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1786. $where[] = ['infoNo','in',$bidinfo];
  1787. }
  1788. $role=$this->checkRole();
  1789. if(!empty($role['write'])){
  1790. $where[]=["createrid","in",$role['write']];
  1791. }
  1792. $count=Db::name("bargain_order")->where($where)->count();
  1793. $total = ceil($count / $size);
  1794. $page = $page >= $total ? $total : $page;
  1795. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1796. $data=[];
  1797. foreach ($list as $value){
  1798. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1799. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1800. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1801. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1802. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1803. if($bidinfos['brand_id']!=0){
  1804. $value['brand_id'] = $bidinfos['brand_id'];
  1805. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1806. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1807. }else{
  1808. $value["brand_name"]="";
  1809. $value["brand_id"]="";
  1810. }
  1811. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1812. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1813. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1814. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1815. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1816. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1817. $value['budget'] =$budget;
  1818. $god=[
  1819. "metal_id"=>$bidinfos['metal_id'],
  1820. "weight"=>$bidinfos["good_weight"],
  1821. "demo_fee"=>$bidinfos["demo_fee"],
  1822. "delivery_fee"=>$bidinfos["delivery_fee"],
  1823. "open_fee"=>$bidinfos["open_fee"],
  1824. "packing_fee"=>$bidinfos["pakge_fee"],
  1825. "mark_fee"=>$bidinfos["mark_fee"],
  1826. "nake_fee"=>$bidinfos["nake_fee"],
  1827. "cert_fee"=>$bidinfos["cert_fee"],
  1828. "cost_fee"=>$bidinfos["cost_fee"],
  1829. "num"=>$bidinfoe["num"],
  1830. ];
  1831. // if($bidinfos['is_gold_price']==1){
  1832. // $price = GoldPrice($god, $budget/100);
  1833. // }else{
  1834. // $price = GoodPrice($god, $budget/100);
  1835. // }
  1836. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1837. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1838. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1839. $data[]=$value;
  1840. }
  1841. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1842. }
  1843. public function crontablist(){
  1844. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1845. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1846. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1847. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1848. if ($zxNo !== "") {
  1849. $where[] = ['a.zxNo','=',$zxNo];
  1850. }
  1851. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1852. if ($salesman !== "") {
  1853. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1854. $where[]= ["b.salesman",'like',"%$salesman%"];
  1855. }
  1856. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1857. if ($cpName !== "") {
  1858. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1859. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1860. }
  1861. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1862. if ($khNo !== "") {
  1863. // $where['khNo'] = $khNo;
  1864. $where[]= ["b.khNo",'like',"%$khNo%"];
  1865. }
  1866. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1867. if ($start !="") {
  1868. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1869. $where[]= ["a.addtime",'>=',$start];
  1870. }
  1871. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1872. if($end !=""){
  1873. $where[]= ["a.addtime",'<=',$end];
  1874. }
  1875. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1876. if ($status !== "") {
  1877. $where[]= ["a.status",'=',$status];
  1878. }
  1879. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1880. ->count();
  1881. $total = ceil($count / $size);
  1882. $page = $page >= $total ? $total : $page;
  1883. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1884. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1885. $data=[];
  1886. foreach ($list as $value){
  1887. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1888. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1889. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1890. $value['khname']="";
  1891. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1892. true):[];
  1893. if($value['khNo']!==""){
  1894. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1895. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1896. }
  1897. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1898. $data[]=$value;
  1899. }
  1900. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1901. }
  1902. }